Cleaning up memory in script
-
What are the best ways of cleaning up memory at the end of a script?
Let's say I use some temp stuff like vectors for example.
Do I need to clean them up with something like:temp_vector = nil
Anything else I need to think about?
-
The Ruby Garbage Collector runs automatically every so often and reclaims memory from all objects to which there is no remaining reference. All ordinary references are released as soon as they go out of scope. So, unless your script is holding references in persistent variables, such as globals, class, and module variables, there is usually nothing more you need to do.
If you think you have generated a lot of dangling objects, you can explicitly initiate garbage collection via methods in the GC module. SketchUp may take a noticeable hit when you do so because everything else must be suspended while the collection takes place. So, if you are creating a lot of small objects (e.g. to assemble Strings piece by piece) it is usually better to rethink your code to pre-allocate larger objects and add data into them incrementally.
-
Thanks.
Advertisement