Ignore:
Timestamp:
Aug 14, 2002, 5:59:18 PM (23 years ago)
Author:
mjs
Message:

Fix major JavaScript memory leak. run-plt says cvs-base improved
by 2% and cvs-js-performance improved by 7%. However, this was
within the possible noise level in each case.

The fix was to store ValueImp *'s in the array instead of Value
objects, since the Value wrapper will keep a ref and make the
object immortal.

  • kjs/array_object.cpp: (ArrayInstanceImp::ArrayInstanceImp): (ArrayInstanceImp::get): (ArrayInstanceImp::put): (ArrayInstanceImp::hasProperty): (ArrayInstanceImp::deleteProperty): (ArrayInstanceImp::setLength): (ArrayInstanceImp::mark):
  • kjs/array_object.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r1799 r1821  
    4444  , length(initialLength)
    4545  , capacity(length)
    46   , storage(length ? new Undefined[length] : 0)
    47 {
     46  , storage(length ? new (ValueImp *)[length] : 0)
     47{
     48  unsigned l = length;
     49  for (unsigned i = 0; i < l; ++i) {
     50    storage[i] = Undefined().imp();
     51  }
    4852}
    4953
     
    5256  , length(list.size())
    5357  , capacity(length)
    54   , storage(length ? new Undefined[length] : 0)
     58  , storage(length ? new (ValueImp *)[length] : 0)
    5559{
    5660  ListIterator it = list.begin();
    5761  const unsigned l = length;
    5862  for (unsigned i = 0; i < l; ++i) {
    59     storage[i] = it++;
     63    storage[i] = (it++).imp();
    6064  }
    6165}
     
    7680    if (index >= length)
    7781      return Undefined();
    78     return storage[index];
     82    return Value(storage[index]);
    7983  }
    8084
     
    8690  if (index >= length)
    8791    return Undefined();
    88   return storage[index];
     92  return Value(storage[index]);
    8993}
    9094
     
    101105  if (ok) {
    102106    setLength(index + 1);
    103     storage[index] = value;
     107    storage[index] = value.imp();
    104108    return;
    105109  }
     
    111115{
    112116  setLength(index + 1);
    113   storage[index] = value;
     117  storage[index] = value.imp();
    114118}
    115119
     
    124128    if (index >= length)
    125129      return false;
    126     return !storage[index].isA(UndefinedType);
     130    return storage[index]->type() != UndefinedType;
    127131  }
    128132 
     
    134138  if (index >= length)
    135139    return false;
    136   return !storage[index].isA(UndefinedType);
     140  return storage[index]->type() != UndefinedType;
    137141}
    138142
     
    147151    if (index >= length)
    148152      return true;
    149     storage[index] = Undefined();
     153    storage[index] = Undefined().imp();
    150154    return true;
    151155  }
     
    158162  if (index >= length)
    159163    return true;
    160   storage[index] = Undefined();
     164  storage[index] = Undefined().imp();
    161165  return true;
    162166}
     
    167171    const unsigned l = length;
    168172    for (unsigned i = newLength; i < l; ++i)
    169       storage[i] = Undefined();
     173      storage[i] = Undefined().imp();
    170174  }
    171175  if (newLength > capacity) {
    172176    unsigned newCapacity = (newLength * 3 + 1) / 2;
    173     Value *newStorage = new Undefined [newCapacity];
     177    ValueImp **newStorage = new (ValueImp *)[newCapacity];
    174178    const unsigned l = length;
    175179    for (unsigned i = 0; i < l; ++i)
    176180      newStorage[i] = storage[i];
     181    for (unsigned i = l; i < newLength; i++)
     182      newStorage[i] = Undefined().imp();
    177183    delete [] storage;
    178184    storage = newStorage;
     
    187193  const unsigned l = length;
    188194  for (unsigned i = 0; i < l; ++i) {
    189     ValueImp *imp = storage[i].imp();
     195    ValueImp *imp = storage[i];
    190196    if (!imp->marked())
    191197      imp->mark();
Note: See TracChangeset for help on using the changeset viewer.