Explict Memory Managment

David Semeria david at lmframework.com
Fri May 22 13:27:42 PDT 2009

On Fri, 2009-05-22 at 11:46 -0700, Brendan Eich wrote:

> As Ash points out, there's no memory-safe way to implement obj.kill()  
> short of a full GC.
> There is no way JS will lose memory safety, ever!
Why can't the deleted object still exist, with its value set to 'null'?

> What's more, we shouldn't expose a gc() call. It would only be abused  
> over time. Even if it were used well at first for a given browser  
> engine (or version), the tendency over time would be for it to be  
> called too much, and for too many (or all) user agents. It would be  
> symptom-treating at best.

I never suggested the GC be exposed

> Explicit memory management is sometimes important, e.g. using a  
> preallocated array or native buffer when pushing pixels. This is not a  
> case where gc() or obj.kill() helps, though.
> If you find poor GC performance, file a bug with the browser vendor or  
> open source project. 

I'm not suggesting GC is not well-implemented. I'm suggesting there
could be a case for the programmer giving the GC a hand.

> If you are using too much memory, reifying large  
> external data sets in JS, don't do that. There's usually a way to  
> avoid taking the all-in-memory hit. SAX-style parsing rather than all- 
> or-nothing blocking parse calls, etc.

This goes back to my initial point regarding complex web apps. There are
many intances where it makes sense to store content in js objects and
then flow it into the DOM using a given template. If the user changes
the template then the information is simply reflowed.

> I hate to generalize, but on the other hand the post asking for  
> explicit memory management was short on specific details -- including  
> ones that might lead to specific browser bugs that could be fixed to  
> the benefit of all developers.

Again, I'm not implying the presence of bugs. I'm suggesting more
complex use cases can lead to situations in which the exiting GC scheme
may not be optimal.

I intentionally didn't go into specifics, but I can provide some real
world examples if you think they would be helpful.

More information about the es-discuss mailing list