[Closed] Memory management techniques
I know maxscript has automatic garbage collection…but I don’t like making garbage.
I know how to call the garbage collection but that’s time consuming and inefficient…
with bitmap’s, you can manually close them down to reclaim the memory.
I’d like to know if there’s a way to do this with arrays?
For instance, I have 2 large arrays…and I say array1 = array2. Now array1 is just a huge memory leak but there seems to be no way to avoid this. I don’t WANT to make memory leaks
because this will cause the garbage collector to have lots of work to do.
hey stuh505, you can say:
array1 = undefined
That should be all you need to do for your example.
cheers,
CML
Rivendale,
MAXScript uses passing by reference, so setting array1 to undefined is simply going to be setting the pointer that points to the location in memory to null, leaving all the memory still there. this is called a memory leak…the garbage collection system will take care of it eventually though.
So you want to have the cake and eat it, too?
After you use memory, release it. I know it takes time to GC it, but that’s life… I am not sure what your question was intended for, you already know how it works.
Ok yes I see, that’s true. Maxscript could use some better ways of dealing with memory. I read somewhere in the reference that this could possibly be added in the future, so that memory is cleared better “as you go along”. I know I wished a lot for this when I developed the Viewport Canvas tools…Would be good to be able to manually clear parts of the memory or sometimes just let it slip right through memory.
CML
So you want to have the cake and eat it, too?
After you use memory, release it. I know it takes time to GC it, but that’s life… I am not sure what your question was intended for, you already know how it works.
Well it’s not much to ask for. I knew that my code would be causing memory leaks, but I didn’t know if there was a way to avoid it…I’m new to max script.
Besides, I’m still not convinced that it can’t be done…perhaps there is a way to trick max into clearing specific memory.
For example, you mentioned earlier today that when a rollout goes out of scope, all it’s local variables are released from memory…and we CAN shut down rollouts. Therefore, we could use rollouts to store large data structures and deallocate the memory by closing the rollout.
Perhaps there is a better way to do this that would not be so apparent to the user.
Actually, I said exactly the opposite – even if you close the rollout, its definition persists in memory. If you redefine the rollout, the old definition STILL exists in memory (and if you never used DestroyDialog, you might even end up with multiple rollouts floating around).
What we are talking here is NOT a memory leak. A memory leak would be memory that is not being released EVEN AFTER GC(). Garbage Collection, both automatic and manual, is meant to free memory when needed. The fact that is might be slightly slow is something to live with, but once the GC has been run, the memory should be released, so no leak…
Nevermind, they are just arrays of pointers anyway…I guess there is just no way.