Comment #5 on issue 2028 by [email protected]: garbage collection issue
http://code.google.com/p/v8/issues/detail?id=2028

Sounds like you should read up on your understanding of variables and the way they reference objects in memory. Do you know what a "pointer" is?

When your code executes, _history and _historyList will initially refer to the same array in memory. If you keep simply keep it that way, you don't need your addedCB callback at all. (You also break any abstraction you intended to have.) Array.push modifies the receiver in place. So after _history.push(newItems) is executed, _historyList still points to the same array object in memory, which has now been modified. Array.concat, however, creates a new object that consists of copies of the parameters to the function. So after _historyList = _historyList.concat(newItems) is executed, _historyList will point to a new object in memory. Therefore, when _history.push() is executed again, the object pointed to by _historyList will not be affected.

This really has nothing to do with garbage collection -- in fact, it has nothing to do with V8 or even Javascript, you could encounter the same situation in C++ or Java or Python or pretty much any language of your choice.

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to