Memory usage during execution
EsMemoryUseReport allows you to compute the amount of nongarbage storage allocated by an executing block. The amount of nongarbage storage allocated by the block is the amount of memory that is still in use after the block finishes execution. EsMemoryUseReport uses the memory reporting primitives to compare the state of memory after the execution of the block to the state before the execution. Any increase is reported to you. You can use the default set of classes (all classes in the image), or a subset of classes that are of particular interest to you.
The following example reports all memory allocated but not reclaimed for all classes during the execution of the block:
"Allocate 1 String and 1 Array and count the allocated memory."
| t1 t2 |
[ t1 := String new.
t2 := Array new ] reportAllocation.
t1 == t2 "Locals are not garbage after the block ends."
Note:
The example could take several seconds to run.
The following report is produced on the Transcript:
Total memory allocated (nongarbage) = 24
Array 1 12 bytes
String 1 12 bytes
The next example reports memory allocated but not reclaimed for a specific class during the execution of the block:
| t1 t2 |
[ t1 := String new.
t2 := Array new ] reportAllocation: (Array with: String).
t1 == t2 "Locals are not garbage after the block ends."
The following report is produced on the Transcript:
Total memory allocated (nongarbage) = 24
Total memory allocated (nongarbage) in selected classes = 12
String 1 12 bytes
The last example reports memory allocated and not reclaimed by all Collection classes when a browser is being opened.
[ EtWorkspace new open ]
reportAllocation: Collection withAllSubclasses asArray.
The report looks like the following:
Total memory allocated (nongarbage) = 28984
Total memory allocated (nongarbage) in selected classes = 11648
Array 85 9032 bytes
String 67 1412 bytes
OrderedCollection 34 816 bytes
ByteArray 15 328 bytes
Dictionary 3 60 bytes
For reports with a large amount of text, it can be slow to send the output to the Transcript. It is often faster to set the output stream to a file stream using the outputStream: message.
Last modified date: 05/19/2020