I observed in NetBeans Profiler that Surviving Generations keeps on increasing after I execute the query:
@Select("SELECT * FROM ais_dynamic WHERE rep_time >= #{from} AND rep_time <= #{to} AND ais_system = #{sys}")
@Options(useCache=false,fetchSize=8192)
List<AisDynamic> getRecords(
@Param("from") Timestamp from,
@Param("to") Timestamp to,
@Param("sys") int sys);
It is as if the objects that are in the list are never released though they are not being used anywhere else and should die with the background thread running the query and processing its results.
Below are the Live Results returned by NetBeans Profiler:
My questions:
- How can I prevent the memory leak?
- How can I optimize this query, as one can see I started playing with the
Options
though this didn't prevent the memory leak?
If anything is needed please do tell what and I will provide.
UPDATE:
After more testing I am more concerned that the problem lays with MyBatis holding a reference to the retrieved results thus they are not garbage collected over time. After doing 20 calls of the query then waiting I observe no garbage collection even after 30 minutes. All that I do is calling the method: List<AisDynamic> adList = mapper.getRecords(from, to, sys);
<settings><setting name="localCacheScope" value="STATEMENT"/></settings>
– partlov