Cleaning up memory in script

Cleaning up memory in script

Postby Pixero » Thu May 25, 2017 9:12 am

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?
0
User avatar
Pixero 
Premium Member
Premium Member
 

Re: Cleaning up memory in script

Postby slbaumgartner » Fri Jun 02, 2017 11:38 pm

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.
1

slbaumgartner 
PluginStore Author
PluginStore Author
 

Re: Cleaning up memory in script

Postby Pixero » Sat Jun 03, 2017 7:37 am

Thanks.
0
User avatar
Pixero 
Premium Member
Premium Member
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: placidfury, ROGEGIAC and 8 guests

Visit our sponsors: