Reputation: 1
I'm pretty new to Java so bear with me here...
I'm using a Scanner to read an InputStream
(which is = Class.class.getResourceAsStream("fileName.csv")
) . When the file is being read, the memory starts around 44,000 and when it's done reading it gets up to 298,000. The class basically reads the inputStream
and puts the data into some ArrayLists
so that I can quickly search through them. The problem is.. I can't figure out how to get the memory usage to go down once the file is done being read. I've tried setting the object = null
and/or calling System.gc()
{which apparently is only a suggestion} but neither work. I'm using the close()
method for both the Scanner
and the InputStream
and nothing has worked thus far. Anyone have any ideas? I guess it's possible I have no idea what I'm talking about and this is how it's supposed to be but I'm pretty sure I'm doing something wrong.
Thanks in advance.
Upvotes: 0
Views: 2003
Reputation: 31
Once you are done using input stream you can set its reference to null, this is the only way you can ask Garbage Collector to free up the unused memory, Since we cannot force GC so there is no way to free memory explicitly.
Upvotes: 2