Memory and garbage collection issues for applications that work with a large number of objects.
If your application uses a large number of objects, and you have enough memory on your system, you can reduce the number of times the garbage collector is invoked by increasing the initial size of the memory allocation pool (the garbage collected heap). This increases performance because most current implementations of the garbage collector take away a significant percentage of CPU time each time they are invoked. If you run out of memory while retrieving a large number of objects from the database, the operation will be slowed down by a large factor. On the other hand, the larger the heap, the longer the garbage collector will take to free memory. This can be offset by manually invoking the garbage collector during periods of low CPU usage (i.e. while waiting for user input).
The default heap size for Sun's java interpreter is 1 megabyte of memory. To specify a 16MB heap use the following switch:
-ms16m
To be able to manually invoke the garbage collector, you must first turn off asynchronous garbage collection by using the java interpreter switch:
-noasyncgc
This allows you to explicitly call the garbage collector by using the following java statement within your application:
Runtime.gc()
The garbage collector should be invoked only when necessary using the amount of free memory as a guideline. Note, however, that there are no guarantees that the garbage collector will actually run as soon as gc() is invoked. To obtain the size of the free memory in the system use:
Runtime.freeMemory()
You may want to test your application's performance using different heap sizes and both garbage collection options.
If you application uses a very large number of objects and they cannot all be loaded in memory at once, use either the listEnumeration methods of the Database object or of collection objects, or restrict the number of objects returned by using specific queries.
© 1998-2001 Objectmatter, Inc. All rights reserved.
TRADEMARKS. Products and company names mentioned herein are the trademarks of their respective owners.