Thanks for your reply Bob, it is for AS2. I read a lot of articles about it and understand the general concept. That is why I post the question. If I understood correctly the posted code should not leave any objects unreferenced and therefor cleared for deleting. But the memory goes up anyway. I tested it with only this two classes instantiated and nothing else.

I am hoping somebody can take a look at the code I posted and give me the reassurence that I am doing things correctly.

Jiri

Bob Leisle wrote:
Hi Jiri,

I'm not sure which AS version you're using but here are some good links on garbage collection in AS3.

http://www.bit-101.com/blog/?p=783
http://gskinner.com/blog/archives/2006/06/as3_resource_ma.html
http://board.flashkit.com/board/showthread.php?t=756290

32000+ more links can be found by googling, "Flash AS3 garbage collection".

hth,
Bob


Jiri Heitlager wrote:
Hello List,

I have two classes Time and Clock, see below. To get good encapsulation,
in the Time class I added a function called clone(). This returns a copy
of the Time instance, instead of a reference to it.
Now I run the code, using an interval that calls the
Clock.getElepasedTime(). While watching the Memory I can see it build
up. Does this mean that with every clone of the Time object it still
holds a reference and therefore doesnt get deleted by the garbage collector.

Hope somebody can enlighten me..

Jiri



class Clock
{

    private var startTime:Number;
    private var elapsedTime:Time;
        //constructor method
    function Clock(tTime:Time)
    {
        clockdata = new ClockData()
        startTime = getTimer();
           }

        public function getElepasedTime() : Time
    {

        var elapsedMilliseconds:Number = getTimer() - startTime;
var elapsedHours:Number = Math.floor( elapsedMilliseconds / 3600000); var elapsedSeconds:Number = Math.floor( elapsedMilliseconds / 1000);
        var elapsedMinutes:Number    = Math.floor( elapsedSeconds / 60);

        elapsedSeconds = elapsedSeconds%60;
        elapsedMinutes = elapsedMinutes%60;

        if(elapsedTime == null){
elapsedTime = new Time(elapsedHours , elapsedMinutes , elapsedSeconds)
            }else{
                elapsedTime.hour = elapsedHours;
                elapsedTime.minute = elapsedMinutes;
                elapsedTime.second = elapsedSeconds;
            }

        return elapsedTime.clone();
               }

}

class Time
{
        private var _hour:Number;
    private var _minute:Number;
    private var _second:Number;
        //constructor method
    public function Time(hour:Number , minute:Number , second:Number)
    {
        _hour = hour
        _minute = minute
        _second = second
    }
        public function get hour() : Number
    {
        return _hour
    }

    public function set hour(nHour:Number) : Void
    {
        _hour = nHour
    }
        public function get minute() : Number
    {
        return _minute
    }

    public function set minute(nMinute:Number) : Void
    {
        _minute = nMinute;
    }
        public function get second() : Number
    {
        return _second
    }

    public function set second(nSecond:Number) : Void
    {
        _second = nSecond;
    }
        public function serialize() : String
    {
        var minutePrefix:String = ( (_minute < 10)    ? '0' : '');
        var secondPrefix:String = ( (_second < 10)    ? '0' : '');
        var hourPrefix    :String    = ( (_hour     < 10)    ? '0' : '');

        return
String(hourPrefix+_hour+':'+minutePrefix+_minute+':'+secondPrefix+_second);
    }
        public function clone() : Time
    {
        return new Time(_hour , _minute , _second)
            }
        }




_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to