After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 552549 - Automatic memory management
Automatic memory management
Status: RESOLVED FIXED
Product: ekiga
Classification: Applications
Component: Engine
GIT master
Other All
: Normal enhancement
: ---
Assigned To: Snark
Ekiga maintainers
Depends on: 557397 557400 557401 557402 557403 557404 562946
Blocks:
 
 
Reported: 2008-09-16 20:36 UTC by Snark
Modified: 2009-06-16 16:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Three tests mentioned (1.52 KB, application/x-compressed-tar)
2008-09-16 20:38 UTC, Snark
Details
Code for automatic memory management (2.62 KB, application/x-compressed-tar)
2008-10-05 21:29 UTC, Snark
Details

Description Snark 2008-09-16 20:36:56 UTC
Currently ekiga doesn't do any automatic memory management : all is manual. That means that when several pieces of code want to share a same object, one must consider itself as owner and free it hoping nothing else still has it. It works because our objects have "removed" signals which makes all sharers forget about it immediately. The problem is that if two "owners" want to share an object, we need to use a SomethingProxy class, so they both can free it. This is cumbersome, and has a size cost -- both for the size of source code (a proxy is long and cumbersome to write) and for the executable code (another class). There is also the problem of what happens when an object emits a form, dies, and the form is submitted : I don't think it can happen as long as we only have gtk+ for the interface, as the form blocks ; but if the DBUS code gets revived, this could bite!

A possible solution is to turn to so-called 'smart' pointers. Unfortunately, they have a quite high size cost (templating mostly means each time we use them on another type, the code is re-implemented by the compiler for us). There is also the problem that although are so many of them, not that many are in the standard namespace. Other problem: how does one make a shared pointer on 'this', which would be needed for the forms issue? Sounds like a need for an intrusive pointer... Do we want to introduce a boost dependancy?

Another solution is to refcount our objects : either we embed the refcount directly in them, and they all grow (and we can have little issues with multiple inheritance), or we store them outside. In either case, both sharing and sending out forms is ok.

I wrote some sample test code to see how things fare. Here are three tests which do the same thing (and make valgrind happy) : they make twenty objects of different types, share them, then free them. One does things manually, one with external refcounts and one with std::tr1::shared_ptr.

Perhaps a mixed solution with external refcounting and a simple home-made smart pointer [very much like boost's intrusive_ptr -- but without the unneeded thread-safe overhead] would be best?
Comment 1 Snark 2008-09-16 20:38:34 UTC
Created attachment 118843 [details]
Three tests mentioned
Comment 2 Snark 2008-10-05 21:29:42 UTC
Created attachment 119986 [details]
Code for automatic memory management

Here is some code, with a two-fold api :
- simple functions to inc/dec a reference count on an object ;
- a smart pointer implementation using the previous.

I store the reference count outside of the objects but still available to them, which allows an object to increment its own reference count (useful to make certain it will still be alive when some C callback gets triggered, for example).

Also in the archive some code using it, to see how it looks.

Comments more than welcome : I'll haunt people to get them.
Comment 3 Snark 2009-06-16 16:40:10 UTC
The call stack is the last place where memory isn't managed by some kind of smart pointer.