[Vala] Singleton and reference count
- From: Jonh Wendell <jwendell gnome org>
- To: vala-list gnome org
- Subject: [Vala] Singleton and reference count
- Date: Tue, 27 Apr 2010 10:46:18 -0300
Hi, folks. I wrote a simple singleton:
public class Prefs {
private static Prefs instance;
public static Prefs default() {
if (instance == null)
instance = new Prefs ();
return instance;
}
private Prefs () {
stdout.printf ("constructor\n");
}
~Prefs () {
stdout.printf ("destruction\n");
}
}
And in the other file, I do:
var prefs = Prefs.default ();
.... use prefs var...
The prefs var doesn't get destroyed, thus my destructor is never called.
Looking at C generated code, I see:
GadePrefs* gade_prefs_default (void) {
GadePrefs* result = NULL;
if (gade_prefs_instance == NULL) {
GadePrefs* _tmp0_;
gade_prefs_instance = (_tmp0_ = gade_prefs_new (), _g_object_unref0
(gade_prefs_instance), _tmp0_);
}
result = _g_object_ref0 (gade_prefs_instance);
return result;
}
It refs the result variable before return. So, there's always a valid
object outside...
How to handle that?
Thanks,
--
Jonh Wendell
http://www.bani.com.br
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]