Object references changing back and forth
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.
On 09/04/2018 at 01:49, xxxxxxxx wrote:
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.
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!