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
Nim Compiler Version 2.2.4 [Linux: amd64]
Compiled at 2025-04-22
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: f7145dd
active boot switches: -d:release
Description
The following example program just appends objects to a sequence. When checking the amount of occupied memory by calling getOccupiedMem it always returns 0 byte even if gigabytes have been allocated. Strangely when using --mm:refc the problem doesn't occur.
Example code
import std/[strutils, strformat]
typeObj=objectofRootObj
name: stringvar l =newSeq[Obj]()
var i =0whiletrue:
var t: Obj=Obj(name: fmt"object #{i}")
l.add(t)
i.inc
if i mod10_0000==0:
echo$i &": occupied mem "&$formatSize(getOccupiedMem())
# ...# 4200000: Occupied mem 0B# 4300000: Occupied mem 0B# 4400000: Occupied mem 0B# 4500000: Occupied mem 0B# 4600000: Occupied mem 0B# ...
Current Output
318867: occupied mem 0B
318868: occupied mem 0B
318869: occupied mem 0B
318870: occupied mem 0B
318871: occupied mem 0B
318872: occupied mem 0B
318873: occupied mem 0B
318874: occupied mem 0B
318875: occupied mem 0B
318876: occupied mem 0B
318877: occupied mem 0B
318878: occupied mem 0B
318879: occupied mem 0B
318880: occupied mem 0B
Expected Output
62287: occupied mem 3.952MiB
62288: occupied mem 3.953MiB
62289: occupied mem 3.954MiB
62290: occupied mem 3.954MiB
62291: occupied mem 3.955MiB
62292: occupied mem 3.956MiB
62293: occupied mem 3.957MiB
62294: occupied mem 3.957MiB
62295: occupied mem 3.958MiB
62296: occupied mem 3.959MiB
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered:
@Araq Yes, I tested it with both and this problem also appears when not passing "--d:useMalloc".
Edit:
I'm sorry, but it appears that the code base I'm working on had a useMalloc defined in the nim.cfg.
I'm reading your response as if this is expected behavior when using malloc instead of Nim's alloc, which makes sense. Do you think we should explicitly mention this in the documentation of getOccupiedMem?
Uh oh!
There was an error while loading. Please reload this page.
Nim Version
Nim Compiler Version 2.2.4 [Linux: amd64]
Compiled at 2025-04-22
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: f7145dd
active boot switches: -d:release
Description
The following example program just appends objects to a sequence. When checking the amount of occupied memory by calling
getOccupiedMem
it always returns 0 byte even if gigabytes have been allocated. Strangely when using--mm:refc
the problem doesn't occur.Example code
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: