I built a slideshow in Actionscript which I have to run in Safari, but I’ve noticed with each image load, Safari’s memory footprint grows and never decreases. I’ve tried placing a delete(variable) after each use of a variable, and adding an mcl.unload(mc) after each transition, but neither has helped. The memory leak doesn’t occur in Firefox or the standalone Flash Player, but I don’t have the option to use browsers/apps other than Safari.
System Info:
Intel Mac Mini 2.0
Mac OS X 10.4.10
Safari 2.0.x
Flash 9
I’m pasting in my code. Before playing the slideshow, the SWF also loads some variables from an external file.
import mx.transitions.*;
import mx.transitions.easing.*;
/* LOAD VARS */
var slideshow_length:Number;
var fade_duration:Number;
var slide_duration:Number;
var idx:Number;
var myVars:LoadVars = new LoadVars();
myVars.onLoad = function() {
slideshow_length = (myVars.slideshow_length ? myVars.slideshow_length : 1);
fade_duration = (myVars.fade_duration ? myVars.fade_duration : 2);
slide_duration = (myVars.slide_duration ? myVars.slide_duration : 10)*1000;
traffic_controller();
};
myVars.load("../vars/my_slideshow_right.vars");
/* END LOAD VARS */
this.createEmptyMovieClip("empty_mc1", this.getNextHighestDepth());
this.createEmptyMovieClip("empty_mc2", this.getNextHighestDepth());
var mcl1:MovieClipLoader = new MovieClipLoader();
_level0.empty_mc1._x = 23.5;
_level0.empty_mc1._y = 47;
_level0.empty_mc2._x = 23.5;
_level0.empty_mc2._y = 47;
/* SWAP DEPTHS */
function swap_containers() {
this.empty_mc1.swapDepths(empty_mc2);
}
/* TRAFFIC CONTROLLER */
function traffic_controller() {
clearInterval(the_delay);
if (idx == undefined || idx>slideshow_length) {
idx = 1;
}
if (current_mc == empty_mc1) {
current_mc = empty_mc2;
}
else {
current_mc = empty_mc1;
}
current_mc._alpha = 0;
mcl1.unloadClip(current_mc);
mcl1.loadClip("../images/rt_slide_"+idx+".jpg", current_mc);
swap_containers();
fade_in_var.onMotionFinished = function() {
delete (fade_in_var);
};
fade_in(current_mc, fade_duration);
get_caption();
the_delay = setInterval(traffic_controller, slide_duration);
}
/* CAPTIONS */
function get_caption() {
fade_out_var.onMotionFinished = function() {
delete (fade_out_var);
};
fade_out(r_caption1_mc, (fade_duration/2));
fade_in_var.onMotionFinished = function() {
delete (fade_in_var);
if (myVars['r_caption'+idx] == undefined) {
r_caption1_mc.r_caption1.text = '';
}
else {
r_caption1_mc.r_caption1.text = myVars['r_caption'+idx];
}
fade_in(r_caption1_mc, (fade_duration/2));
idx++;
};
}
/* TWEENS */
function fade_in(mc, time) {
easeType = mx.transitions.easing.Regular.easeInOut;
var begin = 0;
var end = 100;
fade_in_var = new Tween(mc, "_alpha", easeType, begin, end, time, true);
}
function fade_out(mc, time) {
easeType = mx.transitions.easing.Regular.easeInOut;
var begin = 100;
var end = 0;
fade_in_var = new Tween(mc, "_alpha", easeType, begin, end, time, true);
}