[Closed] MXS unexplained problem… memory leaking
haha… pure insanity
gc()
(
t0 = timestamp()
h0 = heapfree
for k in #{1..1000000} do k
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
)
gc()
(
t0 = timestamp()
h0 = heapfree
for k in #{1..1000000} do (k;ok)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
)
11855884L
time:621 heap:6862476L
11855916L
time:402 heap:184L
check performance for these two:
(
t0 = timestamp()
h0 = heapfree
for k = 1 to 1000000 do (k; ok)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
)
(
t0 = timestamp()
h0 = heapfree
for i=1 to 1000 do for k = 1 to 1000 do k
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
)
ahh… yes. i remember this trick with OK.
but there are another issues when this trick doesn’t work
Yes, you can put ok or 0 or 1 or ? and all will free the heap. But there is still a penalty in the time, I guess it forces the gc() to kick in somewhere in the loop.
Wish to confirm that the “magic” number 3.0 solves all the problems, but it doesn’t work at all in Max 2012. So don’t trust it as a generic solver.
In Max 2013 what it does is to “fix” the leak when getting the third component of the point3, but if I use a point4 value and get the fourth value it still leaks until I declare 4.0. Then getting the fourth value stops leaking.
all these above (and you should remember an issue with big bitarray shown by Swordslayer) forced me to right my own “mxs published” iterator class.
Just checked this nested loops performance and it just doesn’t seem practical to use. Is there any real cases where we could benefit for it?
delete objects
t = Teapot segments:200
addModifier t (TurboSmooth())
convertToMesh t
-- half a million verts test
(
t0 = timestamp()
h0 = heapfree
total = 0
for k = 1 to t.numverts do (getvert t k; total += 1; ok)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
format "%\n" total
)
gc()
(
t0 = timestamp()
h0 = heapfree
iterations = int (t.numverts / 1000)
nv = t.numverts
total = 0
for i=0 to iterations do
(
for k = 1 to 1000 do
(
idx = (i * 1000 + k)
if idx > nv then (k=1000;i = iterations + 1) else ( GetVert t idx; total += 1)
)
)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
format "%\n" total
)
i don’t think i should practice the breaking of long loops on nested sub-loops. it’s kinda weird…
we have to find a way to minimize memory leak because it also causes a performance degradation.
you are looking the leaking in a wrong place. see:
(
gc()
t0 = timestamp()
h0 = heapfree
total = 0
for k in 1 to 100000 do
(
total += 1
ok
)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
format "\t>>%\n" total
)
(
gc()
t0 = timestamp()
h0 = heapfree
total = [0,0,0]
for k in 1 to 100000 do
(
total.x += 1
ok
)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
format "\t>>%\n" total
)
I want to say this again.
Never ignore any memory leaking, don’t believe that memory will return back in the same stage.
There are many cases when the system with automatic gc doesn’t return whole taken memory. sooner or later the system will crash with very well know “Warning” about garbage collect.