Is This Content Helpful?
We're glad to know this article was helpful.
How is the feature cache used when querying shapefile data in MapObjects-Java?
The first invocation of a layer's search() method causes a spatial index to be built in-memory. This process will save each record containing the associated record-id and provide a fast seek location in memory. Note that this event will occur when a Cursor is created from a feature dataset (e.g., a SelectionSet's getSelectedData() method will create a Cursor).
The second invocation of the search() method causes features to be loaded into an in-memory cache up to a limit defined within a resource property file located in esri_mo10res.jar named /com/esri/mo/res/props/cache.properties. The default value is defined by this property:
which means up to 40,960 features may be stored within the cache. Note that the feature will contain both geometry and the attribute values. You can control the memory usage by reducing this property. Note that lower cache values may cause performance degradation since some features will need to be retrieved from disk.
Third and subsequent invocations of search use the cached features when available.
When working with shapefile data, often memory management becomes a problematic issue, especially when dealing with relatively large datasets. Listed below are a few methods to more efficiently manage memory usage in a MapObjects-Java application:
1. Null objects that are no longer needed.
2. When querying a feature layer, instantiate and null all objects associated with the query.
3. Call the dispose method on any Cursor objects once use of the Cursor has finished.
4. Call garbage collection (Runtime.getRuntime().gc()) after nulling objects.
5. Use Runtime.getRuntime().freeMemory() and Runtime.getRuntime().totalMemory() to monitor memory usage. Task Manager often provides invalid information.
6. Modify the feature cache size used by MapObjects-Java 1.0.1 and shapefiles.
Note that MapObjects-Java 2.0 does not use a feature cache for shapefiles. Instead, if the shapefile has a spatial index (.sbn), it will be used. If it does not have a spatial index, an in-memory index will be built.