[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Possible javascript memory leak?
- Subject: [ale] Possible javascript memory leak?
- From: james.sumners at gmail.com (James Sumners)
- Date: Thu, 3 May 2012 08:33:02 -0400
- In-reply-to: <CAAt=rgAyMXVwVKcG9YZP4o29QJwLPMZxZVwU1FsNMt_87NgQnw@mail.gmail.com>
- References: <[email protected]> <CAAt=rgAyMXVwVKcG9YZP4o29QJwLPMZxZVwU1FsNMt_87NgQnw@mail.gmail.com>
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.
>
>
> --
> James Sumners
> http://james.roomfullofmirrors.com/
>
> "All governments suffer a recurring problem: Power attracts
> pathological personalities. It is not that power corrupts but that it
> is magnetic to the corruptible. Such people have a tendency to become
> drunk on violence, a condition to which they are quickly addicted."
>
> Missionaria Protectiva, Text QIV (decto)
> CH:D 59
--
James Sumners
http://james.roomfullofmirrors.com/
"All governments suffer a recurring problem: Power attracts
pathological personalities. It is not that power corrupts but that it
is magnetic to the corruptible. Such people have a tendency to become
drunk on violence, a condition to which they are quickly addicted."
Missionaria Protectiva, Text QIV (decto)
CH:D 59