[thelist] pushing scrollbar to bottom

Kowalkowski, Lee (ASPIRE) lee.kowalkowski at hmrcaspire.com
Wed Oct 19 11:10:32 CDT 2005

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of 
> Christian Heilmann
> Sent: Wednesday, October 19, 2005 2:46 PM
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] pushing scrollbar to bottom
> >
> > I've done something like this before:
> >
> >      <script>
> >       function log(str)
> >       {
> >         var console = document.getElementById("console");
> >         if(console)
> >         {
> >           console.value += str + '\n';
> >           console.scrollTop = console.scrollHeight - 
> console.clientHeight;
> >         }
> >       }
> >
> >       setInterval("log(Math.random());", 500);
> >     </script>
> >   <body>
> >     <textarea id="console" rows="10"></textarea>
> >   </body>
> >
> Ouh, this looks like it leaks memory by the truckload. 

No it doesn't.  It consumes memory in an increasing manner because I'm
repeatedly invoking a function that increases the size of a string in an
object's property.

> If you need to
> use intervals, also make sure you give them a name and clear them
> again.

Clear it when?  It's only ever created once!  And yes, I want it to go
forever, it's only an example.  Fortunately, the setInterval is not required
to do the scrolling, I only put it there to demonstrate the scrolling in an
animated fashion, just so that you don't blink and miss it!  The answer to
the scrolling is the obj.scrollTop = obj.scrollHeight - obj.clientHeight.
My apologies if that wasn't clear.

Intervals don't have names, the setInterval function returns an integer that
you can pass to the clearInterval function.  Calling setInterval many times
without clearing any previously created intervals is technically not a
memory leak, as you would have many intervals running continuously.  This
could be desired, but more probable to be an error in logic, as opposed to a
memory leak, as all intervals would be cleared by the browser when the
browser unloads the page.  If they're not, the memory leak is in the
browser's native code somewhere. 

You're more likely to get memory leaks inside a function called by an
interval, which you cannot remedy by ensuring you capture the interval's
number and clear it!


Our e-mail domain has now changed from iraspire.com to hmrcaspire.com. Please update your address books.

More information about the thelist mailing list