Re: RFC: glocal - automatically freeing memory when it goes out of scope



Le lundi 21 novembre 2011 à 00:00 -0800, Hub Figuière a écrit :
> On 16/11/11 12:05 PM, Mikkel Kamstrup Erlandsen wrote:
> > So; what say you? If there is interest I'll gladly polish it up for
> > inclusion. There are also tonnes of other low hanging fruits like
> > freeing other ref counted types, closing of streams, etc.
> 
> How about a g_autorelease_pool() or something like that? (see
> NSAutoreleasPool in GNUStep / Cocoa)
> 
> For those who don't know, basically you would do a
> g_object_autorelease() on a (refcounted) object you want to unref in the
> short term but keep long enough to be ref elsewhere.
> The actual unref is performed when the outer main loop runs or when the
> autorelease pool is destroy.
> 
> (that's the pattern in GNUStep / Cocoa)
> 
> And it might even actually work with floating references and it does not
> need a specific C compiler extension or C++.

I often though it would be useful to return a ref and unref in an idle
cb, to let a chance to the caller to keep the ownership, and still not
forcing every caller to always have to care about memory management. It
is trivial to implement, but since it is not usual in glib APIs, I never
did it.

Regards,
Xavier Claessens.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]