memory management

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

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

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

memory management

Post by 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
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Post by 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

di.destroy();
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
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Post by 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.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”