Reputation: 1827
I want to create a BufferedImage in a Java-Application. The users are allowed to change the dimensions of the image and I would like to allow images "as big as possible". How can I check, whether creating the BufferedImage would cause an OutOfMemory-Exception and recover from it?
Upvotes: 0
Views: 103
Reputation: 17461
Try to allocate as much as memory when running application.
-Xms256m -Xmx1024M
Above argument will allocate 1GB memory.
Upvotes: 0
Reputation: 2291
Use Runtime.getRuntime().freeMemory()
to check the free memory of your JVM instance. And then based on this value you can add restrictions for dimensions for future image.
Upvotes: 1