memory management

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

User avatar
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

memory management

Postby hungerburg » Sat Dec 03, 2011 4:03 pm

I use the commandline mode to batch-create dxf drawings. Top (the taskmanager) shows that RAM used continously grows. Fortunately, there are not enough iterations to exceed physical RAM. Still, I am curious. Is this some lazy garbage collector in the ECMA interpreter, or do I have to somehow close documents created inside of a loop?

User avatar
Site Admin
Posts: 5195
Joined: Fri Mar 30, 2007 6:07 am

Postby andrew » Thu Mar 01, 2012 11:39 am

I'm looking into memory management in the ECMAScript wrappers at the moment.

Usually, nothing has to be cleaned up as the garbage collector takes care of cleaning up object instances of strings, numbers, RVector, RLine, RLineData, etc.

However, there are some types of objects which have to be cleaned up manually if they are created in ECMAScript:

- RMemoryStorage
- RSpatialIndexNavel
- RDocument
- RDocumentInterface

Documents can for example be created like this:

Code: Select all

var st = new RMemoryStorage();
var si = new RSpatialIndexNavel();
var d = new RDocument(st, si);
var di = new RDocumentInterface(d);

The memory storage and spatial index are owned by the document. The document is owned by the document interface, so cleaning up the document interface is enough in this case:

Code: Select all


Scenes and views attached to the document interface are also cleaned up automatically.

If there is no document interface, you need to destroy the document directly. Similarly, if there is no document (unlikely), you need to destroy the storage and spatial index.

There are also appear to be some Qt classes that need to be cleaned up manually if created in ECMAScript:

- QPrinter
- QPainter
- QXmlResultItems
- QXmlStreamWriter
- possibly more..?

Some of the ECMAScripts from QCAD self need to be fixed to take these things into account, so if you still experience leaks, that might be the reason.

User avatar
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Postby hungerburg » Wed Mar 14, 2012 9:43 pm

Thank You Andrew for the advice. I immediately changed my scripts to destroy any or most of the documentInterfaces created and let it run. I have not taken notes before, only account from my memory, but the savings are worth it. Hundreds of MB turned into tens, whith close to 1000 drawings created.

Return to “QCAD Developers and Contributors”

Who is online

Users browsing this forum: No registered users and 2 guests