Analyzing memory leaks

This page explains how to find memory leaks in case users observe that their image is growing and not shrinking.

Before starting the analysis it might be useful to garbage collect all possible objects

5 timesRepeat: [ Smalltalk garbageCollect ]
  

Observe VM parameters

Usually 1 Old space size and 54 Free old space size are interesting parameters.

GtVmAllParametersReport recordNewReport
  

Compare two different VM parameters snapshots

diff := GtVmAllParametersDiffReport new.
diff recordSourceReport.
  
diff recordTargetReport.
diff
  

If the old space size is just growing, there are memory leaks. To observe figure out what cause those memory leaks, we can use the space tally history, comparing two different snapshots.

Space tally history (see Analysing the image size and its evolution for more details)

GtSpaceTallyHistory default
  

Create a new snapshot

GtSpaceTallyHistory
	recordDefaultSystemWideDataLabeled: ('Snapshot {1}' format: {Time now print24})
  

Compare different snapshots

diff := GtSpaceTallyDiff new 
	sourceVersion: GtSpaceTallyHistory default firstVersion;
	targetVersion: GtSpaceTallyHistory default latestVersion.
  
diff := GtSpaceTallyDiff new 
	sourceVersion: (GtSpaceTallyHistory default spaceTallyVersions at: 4);
	targetVersion: GtSpaceTallyHistory default latestVersion.
  

Once an interesting class is identified, some of their instances can be explored using reference paths

BlEventHandler instanceCount.
  
BlEventHandler allInstances
	in: [ :aCollection | 
		(100000 to: aCollection size by: 400000)
			collect: [ :anIndex | GtReferencePaths to: (aCollection at: anIndex) ] ]