Re: A questiona about memory handling in Gobject based classes



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

last week I had the same question. I assign new memory in the instance_init function (GInstanceInitFunc) and override
the dispose function of the GObjectClass parent class (in the class_init func).

Perhaps this http://mail.gnome.org/archives/gtk-list/2008-November/msg00016.html may help you.

Pablo

Pablo Yánez Trujillo
http://klingsor.informatik.uni-freiburg.de/
My public key: http://klingsor.informatik.uni-freiburg.de/gpg/supertux.asc


Friedrich wrote:
> Ok I read the docs up and down but still am confused.
> Assume I have something like  this
> 
> struct FooObject { 
>        GObject parent;
> }
> 
> struct FooClas {
>     GObjectClass parentClass;
>     /* but then also */
>     some other_struct *struct_pointer;
> }
> 
> 
> Now I have to allocate the struct_pointer dynamically. 
> 
> As I understand this could be done in the _class_init function or
> base_class_init function
> 
> If I put it into the FooClass_class_init function then I expected 
> to have to write  FooClass_finalize function also but 
> if one calls g_type_register_static one can not have a
> class_finalize_function.
> 
> so the only place left seems to be GBaseInitFunc and
> GBaseFinalizeFunc.
> 
> I do not understand when this functins get called. 
> 
> E.g.  what happens if I just have one FooObject and 
> I call g_object_unref on it. The reference counts goes down to 0, so
> I'd think the GBaseFinalizeFunction should be called,  but that does
> not happen. At least a breakpoint isn't hit. 
> 
> In the end my question is how is a ObjectClass structure destroyed?
> 
> Do I have to write special dispose function? 
> 
> Hints for a better understanding of this memory handling stuff would
> be very appreciated.
> 
> Thanks
> Friedrich
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkkdWXcACgkQDzf8xo+0xRXxEwCeNuDzIZsY5ty5W5MuUEAkPfyB
H/YAoOTrUnCii9PI4aXRrGn/j28x6SbB
=B6mi
-----END PGP SIGNATURE-----


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