What happens to objects and docs created in code?



  • On 06/05/2015 at 07:06, xxxxxxxx wrote:

    If I create an object in code, lets say, a Cube and then I perform some operations with it (with SendModelingCommand) and, at sometime I need to create a clone of if (for Current State to Object, for example), if I use the clone in the scene (if I insert it in the scene or I return it as the resulting mesh of an ObjectPlugin), what happens to the original Cube object?
    It gets flushed once the scope leaves the code? Or does it hangs there, taking up memory and I should flush it manually, in code?
    What about documents? If I create a new document, lets say with IsolateObjects , must I flush the document before returning from the code? Or is it flushed automatically once out of scope?



  • On 06/05/2015 at 07:39, xxxxxxxx wrote:

    If you insert a node somewhere, the ownership is transferred to the parent node. Note that both an
    object and a document are both nodes. The reverse is for removing: If you remove a node from
    somewhere, you are taking ownership of that node. In C++, you would need to manually deallocated
    all nodes that you own once you do not need them. But Python will do this for you anyway!

    Interesting fact here: If you use BaseObject::Free(op) to free the object op, all children of op will also
    be deallocated, as are tags and whatever there is that is associated and considered "subordinate" to op.

    If you create an object and a document, both in memory temporarily, both will be freed properly, 
    whether they are "connected" or not (connected = object is inserted in the document). But if you
    choose to insert the document to the document list, they will not be freed since you gave ownership
    to Cinema 4D. When the user closes the scene, Cinema will free the document and the object within.



  • On 06/05/2015 at 07:50, xxxxxxxx wrote:

    Thank you, Niklas.
    So, that means that python will do the house-cleaning and garbage collection for me, once the code is exited, right?
    I was asking this because I assumed that it could have anything to do with the problem I posted here:

    https://plugincafe.maxon.net/topic/8702/11399_object-deselects-everything&PID;=45073#45073



  • On 06/05/2015 at 23:55, xxxxxxxx wrote:

    Hi Rui,

    Originally posted by xxxxxxxx

    Thank you, Niklas.
    So, that means that python will do the house-cleaning and garbage collection for me, once the code is exited, right?

    Exactly. The Python API perform garbage collection when objects are no longer in use.

    Originally posted by xxxxxxxx

    I was asking this because I assumed that it could have anything to do with the problem I posted here:
    https://plugincafe.maxon.net/topic/8702/11399_object-deselects-everything&PID=45073#45073

    This issue has nothing to do with garbage collection and freeing objects.


Log in to reply