[C++-sig] Ownership question.
tALSit de CoD
talsit at talsit.org
Sun Apr 27 09:15:00 CEST 2003
Ok, I think i got ya, but I think that's not what I was saying.
When I do this:
>>> key = cAnimCurveKey ()
Python is in charge of the ownership of the object. So, in theory, the GC
could mark it for collection at any given moment, right?
So if I now add the key to a class that takes it's ownership, what happens?
>>> animCurve.addKey (key) # animCurve is now in charge of deleting the key
is key still managed by python? Will it be marked for collection by the GC?
If so, how do i prevent it?
At 04:00 27/04/2003 -0300, you wrote:
>tALSit de CoD wrote:
>
>>I have a class method that takes ownership of the object passed into it,
>>and I want to know, how do I let boost.python know about this and not to
>>manage that object anymore?
[SNIP SNIP]
>>OOOOORRRRRR Is there a way to specify to boost.python that you don't want
>>it to manage or track that object anymore?
>>
>>Thanks folks
>>Cheers!
>
>
>Unfortunately, I don't think you will get a "nice" way to acomplish this,
>because of how garbage collection works in Python. Consider:
>
> >>> def foo(s):
>... # use s
>... del s # useless, but just to illustrate the point
>...
> >>> x = [1, 2, 3]
> >>> foo(x)
> >>> x
>[1, 2, 3]
>
>So, there's simply no way for a Python function to delete a variable
>passed as parameter... actually, you can't delete any variable and be sure
>that it was actually release, because there could still be references to
>it somewhere else. In python, there's no ownership (you can have
>references with no ownership - weak references), just references to an
>object, that will be disposed when no more references exist.
>
>
>Regards,
>Nicodemus.
>
>>
>>
>> tALSit de CoD | talsit.org
>>
>>
>>_______________________________________________
>>C++-sig mailing list
>>C++-sig at python.org
>>http://mail.python.org/mailman/listinfo/c++-sig
>>
>>.
>
>
>
>_______________________________________________
>C++-sig mailing list
>C++-sig at python.org
>http://mail.python.org/mailman/listinfo/c++-sig
tALSit de CoD | talsit.org
More information about the Cplusplus-sig
mailing list