When I need to destroy RBA objects like Dpoint or DPolygon to avoid creating dead objects?

Hi all,
When I do something like this inside a method which I call often:
...
p = [ DPoint::new(0, 0), DPoint::new(6000, 0), DPoint::new(6000, 3000), DPoint::new(0, 3000) ]
poly = DPolygon::new(p)
view.zoom_box(poly.bbox.enlarged(10.0,10.0))
marker.set_polygon(poly)
...
and I do not call _destroy for the DPoints, the DPolygon and the implicitly generated DBox
do I generate a lot of dead objects occupying my memory?

Or do I have to write:
...
p = [(a=DPoint::new(0, 0)), (b=DPoint::new(6000, 0)), (c=DPoint::new(6000, 3000)), (d=DPoint::new(0, 3000)) ]
poly = DPolygon::new(p)
a._destroy; b._destroy; c._destroy; d._destroy
view.zoom_box(a=poly.bbox.enlarged(10.0,10.0))
a._destroy;
marker.set_polygon(poly)
poly._destroy;
...
???
Thank you in advance.
Frank
Ps: What tag could I use to create the nice colored code snipplets?
test=test

Comments

  • Hi,

    last question first: you can use Markdown here. My way to marking code is to separate code by a single like with three backticks.

    Regarding the "_destroy" question: Basically you don't need to destroy objects at all. In Python and Ruby, objects are destroyed when they are not longer required. In Python this happens through reference counting, Ruby has a garbage collection scheme which occasionally cleans up memory.

    However, there are some scenarios this method can be useful:

    • When you're coding UIs with Qt: the visibility of UI object is correlated with their lifetime. If you want to remove an object from a UI by deleting it, you have to use _destroy. Otherwise you might have to wait until the garbage collector hits again.
    • When you have objects that consume a lot of memory: if you manage layout objects and load a lot of data into them, you may want to get rid of the memory they occupy once you do no longer need them. IN this case, call _destroy to free their memory.
    • In DRC scripts when a layer is not longer required, you should consider using the equivalent of "_destroy", which is called "forget" in DRC.
    • When an object allocates a system resource such as sockets or file handles. Qt's network system is such a case.

    Regards,

    Matthias

Sign In or Register to comment.