Re: RFC: glocal - automatically freeing memory when it goes out of scope
- From: Mikkel Kamstrup Erlandsen <mikkel kamstrup canonical com>
- To: gtk-devel-list gnome org
- Subject: Re: RFC: glocal - automatically freeing memory when it goes out of scope
- Date: Tue, 22 Nov 2011 09:03:27 +0100
On 11/21/2011 04:54 PM, Hub Figuière wrote:
On 21/11/11 07:34 AM, Mikkel Kamstrup Erlandsen wrote:
This is precisely my motivation for introducing this; ie. not to catch
leaks, but to tidy the code. Bigger code bases almost always grow
functions with multiple returns - notably when error handling is
introduced. Automatic freeing can cut down on that complexity
considerably. On less complex functions it can still add clarity by
making the actual algorithms more apparent in between all the g_free()s
and g_object_unref()s.
Which is basically what my counter-proposal of g_object_autorelease() is
about.
That's exactly the use case in Objective-C with Cocoa that, unlike C++,
does not have scope based life cycle of object, but supports exceptions.
Also to make it more useful with Glib, we would need to have actually
containers implemented as GObjects.
I am guessing that you expect this autorelease pool to trigger a garbage
collection in an idle call on the mainloop or something?
Assuming "yes"; I can see that this has its use cases, but also some
pretty huge drawbacks. Like 1) needing a mainloop, and 2) being
susceptible to memory ballooning with something like a for-loop doing
lots of string manipulations. And 2) is a very common use case for
automatic cleanup since looping often has a few early-breaks with the
required extra cleanup logic.
That said, I am not against the concept either. It does have the
advantage on ref counted types that any function on the call stack can
grab a ref before the next idle. So it can work over returns and such.
Cheers,
Mikkel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]