Re: [Vala] Singleton and reference count



On Tue, 2010-04-27 at 10:46 -0300, Jonh Wendell wrote:
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. 

You probably want to make default return an "unowned Prefs" instead of
just "Prefs", that way the reference count is never increased.  I might
be terribly wrong though, I am still not very fluid with vala's memory
management.

Sam

Attachment: smime.p7s
Description: S/MIME cryptographic signature



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