Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    What happens to objects and docs created in code?

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 428 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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://developers.maxon.net/forum/topic/8702/11399_object-deselects-everything&PID;=45073#45073

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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://developers.maxon.net/forum/topic/8702/11399_object-deselects-everything&PID=45073#45073

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post