Hi guys, thanks to all for the answers, I really appreciate that.
Rob Camick, I will give a try to your code tomorrow when I'll go back to my office, thanks very much.
Campbell Ritchie, you said you tried that code with your photo and used about 66Mb.
I didn't check with jconsole but windows task manager is enough for me to see the increasing usage of memory.
So, 66Mb is not much, nut you didn't tell us if that memory is deallocated after the window is closed and that's the issue.
Let's say I open and close a window with a 66Mb picture 20 times, not the same picture and not the same window.
20 different windows with 20 different images.
If the memory is not deallocated each time sooner or later you will get an out of memory error.
For me the thing is faster because I use bigger images that increase like 200/300Mb every time they are loaded, and I have not only 3 windows but plenty of them.
That's said, this is not the point.
The fact that you didn't have errors with a few images of 66Mb is not telling me if the memory is still increasing or not (in mine the answer is yes, I never had a memory decrease, only increase).
As I said, the point is: why the memory is not deallocated after disposing the window?
Carey Brown, I'm sorry if I didn't give you more information, but my original question was more "theorical"...
What is the correct way to dispose a window (JFrame, JDialog or even a single JLabel) in order to avoid memory leak?
Speaking of practical stuff, the piece of code with 3 buttons throw an exception, just try with much bigger images, something big enough to raise the memory allocation to 400/500Mb.
You don't need to replicate the error, just take a look at the task manager and you will see that the memory allocation keep on growing and never decrease after the windows are closed.
No corrupted images, just take very big ones, but, again, that's not the point. With smaller images the thing will happen again with more iterations.
In my opinion I'm doing something wrong that didn't deallocate the memory when I close the windows.
Please, answer me a question: is the memory decreasing when you close the windows? If not something is wrong...