[ale] Possible javascript memory leak?
Jim Lynch
ale_nospam at fayettedigital.com
Thu May 3 13:43:49 EDT 2012
Hi, James,
Thanks for the suggestion. I'll give it a try a little later.
Jim.
On 05/03/2012 08:33 AM, James Sumners wrote:
> I forgot to add a "$imgContainer.remove()" after the replacement and
> before re-caching. That's the key part, so you should add that in.
>
> On Thu, May 3, 2012 at 8:31 AM, James Sumners<james.sumners at gmail.com> wrote:
>> The browser is probably retaining all of the images in memory. I would
>> try removing the image element and adding a new one each time:
>>
>> $(document).ready(function()
>> {
>> var $imgContainer = $('#img-container'),
>> r = 0,
>> refreshId = {};
>>
>> refreshId = setInterval( function()
>> {
>> r = (-0.5)+(Math.random()*(100));
>> console.log(r);
>> $imgContainer.replaceWith([
>> '<img src="img.php?h=',
>> r,
>> '" id="img-container">'
>> ].join(''));
>>
>> // re-cache the reference for the next run
>> $imgContainer = $('#img-container');
>> }, 3000);
>> });
>>
>> On Thu, May 3, 2012 at 6:51 AM, Jim Lynch<ale_nospam at fayettedigital.com> wrote:
>>> I'm running a small javascript script using the setInterval function.
>>> Under both Chrome and FF it leaks memory, or at least it keeps consuming
>>> memory until the system crashes, or freezes up.
>>>
>>> Here's the script.
>>>
>>> $(document).ready(function()
>>> {
>>> var refreshId = setInterval( function()
>>> {
>>> var r = (-0.5)+(Math.random()*(100));
>>> console.log(r);
>>> $('#img-container').attr('src','img.php?h='+r);
>>> }, 3000);
>>> });
>>>
>>> Is there something wrong with it? Any suggestions on how to cure the
>>> problem without restarting the browser? The php code reads a .png file,
>>> adds a bit of text to it and outputs it so it is displayed.
>>>
>>> Thanks,
>>> Jim.
>>
>> --
>
>
More information about the Ale
mailing list