Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
30.3 VisualWorks memory m<strong>an</strong>agement<br />
Maximum<br />
Memory<br />
OldSpace<br />
PermSpace<br />
<strong>Object</strong><br />
Memory<br />
LargeSpace<br />
NewSpace<br />
<strong>Object</strong> Engine memory<br />
<strong>Object</strong> Engine<br />
0<br />
Virtual Machine<br />
Figure 30.1: Memory org<strong>an</strong>ization in VisualWorks<br />
VisualWorks provides automatic memory m<strong>an</strong>agement. Essentially it does so by allocating a portion<br />
of memory as <strong><strong>an</strong>d</strong> when required. Then, when memory is short it searches through memory looking for<br />
areas which are no longer referenced. These areas of memory are then freed up (deallocated) so that<br />
they c<strong>an</strong> be re -allocated. This process is often referred to as “garbage collection”. A second process,<br />
invoked with garbage collection is memory compaction. This involves moving all the allocated memory<br />
blocks together so that free memory is contiguous rather th<strong>an</strong> fragmented. The <strong>Smalltalk</strong> memory is<br />
divided up as shown in Figure 30.1.<br />
As c<strong>an</strong> be seen from this figure there is <strong>an</strong> area of memory allocated to the Virtual Machine (the<br />
object engine). This area, below the black line, holds both the virtual machine <strong><strong>an</strong>d</strong> the memory it uses.<br />
This area is outside the scope of this book <strong><strong>an</strong>d</strong> will therefore not be considered in greater detail.<br />
The regions in the <strong>Object</strong> Memory are used to hold the objects created by the system <strong><strong>an</strong>d</strong> by user<br />
programs. It is useful to distinguish between parts of this memory, not least because the VisualLauncher<br />
offers the user two different types of garbage collection, one called “Garbage Collection” <strong><strong>an</strong>d</strong> one called<br />
“Global Garbage Collection”. The options relate to which parts of memory are processed.<br />
30.3.1 NewSpace <strong><strong>an</strong>d</strong> OldSpace<br />
NewSpace is fixed in size (the default for NewSpace is about 200 K) <strong><strong>an</strong>d</strong> is used to hold newly created<br />
objects. When the amount of memory used in NewSpace crosses the scavenge threshold , the<br />
“generation scavenger” is called. This is a program which frees up memory from objects wh ich are no<br />
longer referenced. This memory c<strong>an</strong> then be used again. If <strong>an</strong> object has survived for long enough it<br />
may get moved in OldSpace.<br />
References to objects in OldSpace are not quite as fast as those to objects in NewSpace, however,<br />
OldSpace is not fixe d in size <strong><strong>an</strong>d</strong> c<strong>an</strong> grow as long as there is memory available. The scavenger does<br />
not operate in OldSpace as it is optimized for NewSpace h<strong><strong>an</strong>d</strong>ling objects which are rapidly created <strong><strong>an</strong>d</strong><br />
then de-referenced.<br />
30.3.2 LargeSpace<br />
This is a special area of memory for very large byte objects (typically larger th<strong>an</strong> 1 KB) e.g. bitmaps.<br />
This saves the need to move large areas of memory around because of small frequently used areas of<br />
memory being repeatedly allocated <strong><strong>an</strong>d</strong> deallocated. <strong>Object</strong>s in LargeSpace are only freed up or moved<br />
when LargeSpace is compacted as part of a “compacting garbage collection” or when LargeSpace has<br />
filled up.<br />
258