> 2) add a template specialization like CppPyObject<T*> that uses delete 
> instead of calling the destructor directly
The problem here is that AFAIK there is no way to define such template 
specializations for functions. We could still introduce new functions 
CppDeallocPtr() CppOwnedDeallocPtr().

> 3) use smart pointers (std::auto_ptr, or better, boost::shared_ptr) instead 
> of naked pointers
If python-apt were to use smart pointers, this could be a problem for 
applications wanting to provide their objects in python-apt using the planned 
C++ API of the upcoming python-apt 0.8. Furthemore it does not make sense to 
have two reference counters for basically one 'thing' (the CppPyObject itself 
and the pointer to the C++ object).

> The second option would be easy to implement, but what if you wanted a
CppPyObject to contain a pointer without > deleting it? The first option
is too restrictive. Probably, the third option makes the most sense.

The third option makes no sense because we would force all programs
wanting to export their objects to python to use smart pointers. The
second option makes most sense here, but we should introduce a new
member 'ShouldDealloc' or similar which can be set in
CppPyObject_NEW()/CppOwnedPyObject_NEW() and prevents the deallocation.
This way, providing a C++ API still works and the program is still
responsible for deleting the object, instead of some class somewhere.

I have committed the attached patch to the jak branch and it will be
part of the 0.7.92 release.

** Attachment added: "python-apt-fix-memleaks.diff"
   http://launchpadlibrarian.net/27830657/python-apt-fix-memleaks.diff

-- 
Multiple memory leak in ALL versions of python-apt
https://bugs.launchpad.net/bugs/370149
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to