Memory Implications Of Passing Literals/objects/classes To Functions With Thousands Of Calls
Background A framework I'm writing involves a Figure class calling a function SetTranslate( x, y ) on a Renderer class. In turn, the Renderer class has to store the arguments (x, y
Solution 1:
I think you will find that object pools are a very effective way of controlling the memory behaviour of something like this. Allocate up front the number of objects that you need concurrently and then reuse them to avoid garbage collection issues.
To answer your question,
aRenderer.setTranslate( { x: this.rect.x, y: this.rect.y } );
will create a new object and yes, in your example the previous translate object would be eligible for GC (assuming there are no other references to it).
Post a Comment for "Memory Implications Of Passing Literals/objects/classes To Functions With Thousands Of Calls"