Since JOAFIP make able to manage more objects than memory can
contains, it is important that all objects read or wrote are deleted
from memory when data access session is closed.
To check if achieving the goal a tool has been add to detect memory leak. This the role of MemInspector class to create list of object in memory ( weak references ) and make able to see added object from an object list to another. All object in memory have a reference path from the root object.
checking file persistence
/* get the memory inspector service instance */
final MemInspector memInspector = MemInspector.getInstance();
/* Only interested by creation of object from joafip package class */
* After doing initialization and some object storing, get the object in
* memory in initial object map.
memInspector.inspect(this, false/* markNew */);
/* add an object */
* Get the object in memory and log those added to initially in memory
memInspector.inspect(this, true/* markNew */);
* is there object added
System.out.println("added object :"+memInspector.added());//NOPMD
* output in text file
final PrintStream stream = new PrintStream(new File("runtime/mem.txt"));
* output for ShowObjectTree
Below the log obtained, this is the objects that stay in memory after a data access session usage. A path to object staying in memory to root object is also log for debug purpose.
class net.sf.joafip.meminspector.MainTestMemInspector 20181463
* class net.sf.joafip.store.service.objectfortest.Bob1 9042915
= class net.sf.joafip.store.service.objectfortest.Bob2 32425490
+ class net.sf.joafip.store.service.objectfortest.Bob3 6794265
Or using net.sf.joafip.meminspector.service.ShowObjectTree