You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Object destructor not called when reassigning after a try-except block.
Minimal example:
import std/os
typeMyObj=object
data: pointer
size: intprocinitMyObj(size: int): MyObj=assert size >0result.data =allocShared0(size)
result.size = size
# imitate worklet p =cast[ptrUncheckedArray[uint8]](result.data)
for i in0..<size:
p[i] = i.uint8proc`=destroy`(x: MyObj) =ifnot x.data.isNil:
deallocShared(x.data)
proc`=wasMoved`(x: varMyObj) =
x.data =nil
x.size =0proc`=copy`(x: varMyObj, y: MyObj) {.error.}
procmain() =whiletrue:
var obj: MyObjtry:
obj =initMyObj(10_000_000)
except:
# except FloatOverflowError: also causes a leak, although it is never raisedbreak# discard obj
obj =MyObj()
sleep(20)
echogetOccupiedMem()
main()
Uncommenting the discard obj line removes the issue.
Nim Version
Both on
Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-07-03
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf
active boot switches: -d:release
and
Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-12
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: 793cee4de1934fd1f6271cf5fed46f01c5abb19b
active boot switches: -d:release
Description
Object destructor not called when reassigning after a
try-except
block.Minimal example:
Uncommenting the
discard obj
line removes the issue.Nim Version
Both on
and
Current Output
Expected Output
Known Workarounds
In the example above, uncommenting the
discard obj
line removes the issue.Additional Information
No response
The text was updated successfully, but these errors were encountered: