Strange behavior of 'del' command..
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Sun Feb 27 14:22:58 EST 2000
Kim Jeong Ju wrote in comp.lang.python:
> I am currently into embedding & extending Python to my C++ project.
> And I found some strange behavior of 'del' command.
>
> It's about deleting Python object which was instantiated from wrapped
> C++ class.
>
> For example, let's say 'my_object' is a instance of wrapped C++ class.
>
> >>del my_object
>
> This works just fine. It exactly calls the destructor of C++ class and frees
> memory blocks as it supposed to do.
Actually, all it's supposed to do is remove the name from the current
namespace. _If_ nothing else is still referring to it, then it may be
removed, and the destructor would be called then. You can't assume that
'del' will call your destructor.
Repeat: del only deletes a name from the namespace.
> And here is the weird one
>
> >>exec( 'del my_object ' )
>
> The destructor should be called like above one. But It didn't..
> Still the symbol name was deleted.
>
> >>my_object
> Traceback( innermost last ):
> ..
> Name error: my_object
>
> Isn't it strange? If you got an idea what happend, please let me know
> about it.
It works fine for me in a simple test case. You probably still refer
to the object somewhere else. Is it still part of some list, or something?
We need more info about your code.
--
Remco Gerlich, scarblac at pino.selwerd.nl
8:17pm up 96 days, 2:21, 7 users, load average: 0.16, 0.14, 0.13
More information about the Python-list
mailing list