Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

My First Widget! Memory Leak reloading images...



Hi Everyone,

I am developing my first widget that displays a basic image from the internet that is refreshed every minutes.
I implemented the onshow and onhide to avoid refreshing the image permanently.

All look to be working very well.

The big problem is that each time the image is re-loaded from the Internet I gain an additional 2MB in my widget process memory!
So I got a memory link! How can I release my old image? Thought it was automatic? Do not really understand what is happening.

I am refreshing the image with a timer that uses a new _javascript_ image object and that calls the onload callback and then reloads the picture doing a new <img> tag in a <div> space (as you can see in the attached code).

Can you help me?

Thank you very much in advance for your help!
All the best,
Eric.


Sorry if this looks like hell, this is my first web/_javascript_ code :)


function refresh(url)
{
    loadImage(url + '?' + Math.floor(Math.random() * 1000), gWidth, gHeight);
}

function loadImage(url, width, height)
{
    var tmpimage = new Image(); 

        

    tmpimage.>
    tmpimage.>
    tmpimage. width, height);

    

    tmpimage.src = "">
}

function imageLoaded(url, width, height)
{
    var results = document.getElementById("results");
    var    tmpresults = "";

        

    tmpresults = '<img STYLE="position:absolute; LEFT: 6px; TOP: 6px; WIDTH: ' + width*gRatio + 'px; HEIGHT: ' + height*gRatio + 'px;" id="image" src=""Apple-style-span" face="Monaco"> + url + '"></img>';

    results.innerHTML = tmpresults;

    

    window.resizeTo(width*gRatio+18, height*gRatio+18);
    backimage.width = width*gRatio+18;
    backimage.height = height*gRatio+18;
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.