That's not a singleton, as every time you call the public static constant, it
creates a new instance.
The static var should be private and the class needs an access point method,
usually called getInstance();
private static var INSTANCE:AppApi;
public function AppApi():void {
if (INSTANCE != null ) {
throw new Error("Only one instance allowed. " +
"To access the Singleton instance, use getInstance().");
}
}
public static function getInstance():AppApi{
if(!INSTANCE) INSTANCE = new AppApi();
return INSTANCE;
}
Then elsewhere in your app you refer to the singleton with:
AppApi.getInstance();
----- Original Message -----
From: "ktu" <ktu_fl...@cataclysmicrewind.com>
To: "Flash Coders" <flashcoders@chattyfig.figleaf.com>
Sent: Friday, September 20, 2013 3:18 PM
Subject: Re: [Flashcoders] static const singleton & GC?
anybody have any ideas?
this is still shaking my boots.
thanks :)
On Mon, Sep 16, 2013 at 5:53 PM, ktu <ktu_fl...@cataclysmicrewind.com>wrote:
hey all!
I'm faced with an interesting question.
in my codebase, we made the decision to use a few singletons. to implement
those singletons we used the static const trick:
package com.example {
public static const API:AppAPI = new AppAPI();
}
package com.example {
public class AppAPI {
public function AppAPI () {
if (API) throw new Error();
}
}
this works fine in the normal environment we run in. that is, we run in a
scheduler system that loads the flash player, runs our swf, then shuts down
the flash player, doing that over and over again based off the schedule of
content. the problem now is that a new client uses a scheduler that is
built on AIR, so the flash player instance never shuts down. whenever our
app comes up in the scheduler, memory jumps and never goes down causing the
AIR app to crash every couple of hours. If, they load my application only
once, and leave it running, it lasts for days without any major memory
leaks.
any idea how i could test whether GC does pick this up or could? or any
known issues with this trick and GC? maybe you just have tricks in general
to finding out what GC isn't getting?
thanks!!!
--
Ktu;
The information contained in this message may or may not be privileged
and/or confidential. If you are NOT the intended recipient,
congratulations, you got mail!
--
Ktu;
The information contained in this message may or may not be privileged
and/or confidential. If you are NOT the intended recipient,
congratulations, you got mail!
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders