• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileItem .get() grows Memory Consumption  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I fuond my code get big memory consumption on runtime.

Here is the simple code:


I am using commons-fileupload-1.3.1 jar
I run that simple code using an upload of a jpg test image having size 112MB (for testing purpose)
Before run, my task manager (win 7) shows that Java used 67MB of memory.
After run, it grew to 192MB and not releasing. (and it grows at such pace if I repeat the process)
I see that the memory may be leak.
Could anyone help me?

Thank you
 
Ranch Foreman
Posts: 3074
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a memory leak.
Java grabs a chunk of memory from the OS when it needs it.
That does not represent the memory actually used by your program, though.
It's just the heap (plus extras) that the JVM thinks it might need.

When a GC occurs then all that happens is that some of that heap is freed up to the JVM, but not necessarily to the OS.

If you want to see heap usage then you need to use a heap analysis tool, not the TaskManager.

Besides that point, there is also no guarantee that a garbage collection will have run at the end of that code, so your heap may still show that space being used.
 
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
When a GC occurs then all that happens is that some of that heap is freed up to the JVM, but not necessarily to the OS.



Some time (and several versions) ago I tested whether the JVM was willing to return no longer used memory to the OS.
Some JVM's were and some were not. Well, it depended on the Java version but not on the OS (Windows or Linux).
 
Elissis Bowy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:That's not a memory leak.
Java grabs a chunk of memory from the OS when it needs it.
That does not represent the memory actually used by your program, though.
It's just the heap (plus extras) that the JVM thinks it might need.

When a GC occurs then all that happens is that some of that heap is freed up to the JVM, but not necessarily to the OS.

If you want to see heap usage then you need to use a heap analysis tool, not the TaskManager.

Besides that point, there is also no guarantee that a garbage collection will have run at the end of that code, so your heap may still show that space being used.


Thanks Dave, I am going to utilize Heap Analysis tool to analyze further.
But for the meanwhile, it seems that the memory used by JVM grows each time the code is called, as if the heap not being reuse

For more info, when I call this code, memory doesn't grow crazy
 
Elissis Bowy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yeahh, after installed YourKit, I could see the heap was piling up call after call of that code.
But then, a call to System.gc() cleared the heap.
I guess it is a solution for me
Any suggestion or input?
 
Dave Tolls
Ranch Foreman
Posts: 3074
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should never in normal usage have to call gc() explicitly.

Do you hit an OutOfMemoryError?
If not then I don't (immediately) see the problem.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Elissis Bowy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:You should never in normal usage have to call gc() explicitly.

Do you hit an OutOfMemoryError?
If not then I don't (immediately) see the problem.


At least I know that the memory cleared when gc() is called, and I will let JVM call the gc() by itself.
Well, in runtime, my web occasionally gets permgenspace exception, that's why I started to investigate a little.

Thank you

Campbell Ritchie wrote:And welcome to the Ranch

Thank youu
 
Dave Tolls
Ranch Foreman
Posts: 3074
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A PermGen OutOfMemory exception is not the same thing as a heap OOM.
The former is all about the loading of classes.
You might hit it if you do a lot of hot deploys, for example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!