3

We have created a GroupByVisitor with the following code:-

GroupByVisitor visitor = new GroupByVisitorBuilder().withAggregateAttribute(CQL.toExpression(strColumn))
                .withAggregateVisitor("Count").withGroupByAttribute(CQL.toExpression(strColumn)).build();

At this point the memory in use is 150-180Mb . and after applying this with the following code:-

sfc.getFeatures().accepts(visitor, null);
visitor.getResult()

after this point memory crosses 1800Mb. but not release after this. How to release memory in this after we get all the values?

even System.gc(); has not release all the memory.

1 Answers1

2

From a quick read of GroupByVisitor, the result class GroupByResult likely holds a reference to a member of the GroupByVisitor.

From how the code is working, as long as your code holds a reference to the object returned by 'getResult', then there is a reference to the Visitor (and its data structures).

The JVM may collect the memory if you are able to copy the data out of the returned object and then pass out of context where the result and visitor have references.

GeoJim
  • 1,320
  • 7
  • 12
  • i understand your point, but in my scenario nothing is referenced , I just use `visitor.getResult().toArray();` and after that i have a loop on my resulted array. my question is not about `GroupByVisitor` its about `GetFeatures()` . In simple words how can i release memory after calling `GetFeatures` on a `SimpleFeatureSource`? – Shubham Goyal Feb 28 '17 at 10:12
  • Memory management in the JVM is a complex topic. As a really, really quick suggestion, you could extract your code which creates the visitor, calls it, and loops over the results into a function. After you return from that function, calls to System.gc() might have a better chance of collecting the memory. As another caveat, the garbage collector can decide not to collect memory which is free if there is enough memory free otherwise.;) – GeoJim Mar 01 '17 at 13:57
  • thx but thats not help me. I have already called `System.gc()` but not releasing any memory. – Shubham Goyal Mar 02 '17 at 05:02
  • Do you have a sample of that code? If you are calling gc() from a context with a reference to the classes above, the garbage collector will not be able to reclaim any of the objects involved. – GeoJim Mar 06 '17 at 13:39