for a periodic table tool I’m making, I’ve incorporated an effect that changes the alpha value whenever I hover over an element (pretty standard).
I’ve noticed a mysterious gain in memory when hovering over my elements; using SYSTEM.TOTAL_MEMORY – there would be about 0.005MB increase in memory usage when I hover over an element, which isn’t relinquished when I move my mouse off. However, if I move my mouse back on again, there isn’t a second memory gain.
By commenting out bits of the function, I’ve noticed that it’s the alpha change that is causing this – here is the code for it:
addEventListener(MouseEvent.MOUSE_OVER,highlightthis);
addEventListener(MouseEvent.MOUSE_OUT,dehighlight);
function highlightthis(evt:MouseEvent):void
{
if (evt.target is Element)
evt.target.alpha = 0.5;
}
function dehighlight(evt:MouseEvent):void
{
if (evt.target is Element)
evt.target.alpha = 1;
}
Does anyone know why this memory gain is happening when the alpha value is changed? And curiously why it only happens once?
Some extra info: my Element class is a MovieClip, with a couple of TextFields, primitive variables and a MovieClip in it. It has had its mouseChildren property set to false (and buttonMode property set to true).
This may be a shot in the dark, I don’t know the reason, but could try to guess. Transparency requires knowing the color of the background, besides, in order to display transparency, you’d need one more byte of information (in BitmapData) per pixel (i.e. 33% increase RGB -> ARGB). So, once the player knows the solid color it doesn’t bother to save the invisible background, once the background becomes visible it, naturally, needs more memory to save the color info. Once that happens it either caches that info, or you simply didn’t wait until GC cycle.