memory management
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
- hungerburg
- Premier Member
- Posts: 160
- Joined: Fri May 28, 2010 7:35 pm
memory management
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?
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:
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:
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.
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);
Code: Select all
di.destroy();
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.
- hungerburg
- Premier Member
- Posts: 160
- Joined: Fri May 28, 2010 7:35 pm