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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Object references changing back and forth

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 666 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 09/04/2018 at 01:11, xxxxxxxx wrote:

      OK, so the address changes, because the variable is pointing to a different Python object. Makes sense. So, the address shown in the console is not the C4D BaseObject's address, but the Python object's address.

      But why are there only two addresses, and not always a completely new address?
      ~~
      ~~
      And if they're different Python objects referencing to the same (and unchanged) C4D BaseObject, why does a GetGUID() call to the BaseObject also return a different result?
      [EDIT]Oops, it does not always do that. Seems that the different GUIDs are another issue in my own code.[/EDIT]

      I'll have a look into GeMarkers, though, thanks.

      Cheers,
      Frank

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

        On 09/04/2018 at 01:49, xxxxxxxx wrote:

        Hi Frank

        As said before, variable in python is a reference to a Python Object, for each python object you get a reference count (in order to avoid to get 100 times the same object in the same state in the memory represented by multiple variables).
        So basically when you are creating a variable in python you actually, create a python object, then you add 1 to the reference count of this python object.
        When the reference count of an object equals to 0, the python garbage collector deletes it.

        So in your case at the end of the loop (which is a local scope), python delete the variable "obj", so the pointed python Object reference count is back to 0, then the python garbage collector is "executed" and the object is deleted.
        Then for the next loop, a new object needs to be created and so on...

        About memory address, it's some memory optimization, but in fact, if you got other jobs in parallel, the address may be completely arbitrary and it's doesn't matter. 
        In python, it's really not recommended to diff object based on the memory address, but on hash function based on some members of the objects.

        If you have any questions feel free to ask.

        Cheers,
        Maxime

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

          On 09/04/2018 at 03:20, xxxxxxxx wrote:

          I got it working. Thank you so much for the explanation and the very very helpful link to the GeMarker posting!

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