How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size) -


i writing client-side swing application (graphical font designer) on java 5. recently, running java.lang.outofmemoryerror: java heap space error because not being conservative on memory usage. user can open unlimited number of files, , program keeps opened objects in memory. after quick research found ergonomics in 5.0 java virtual machine , others saying on windows machine jvm defaults max heap size 64mb.

given situation, how should deal constraint?

i increase max heap size using command line option java, require figuring out available ram , writing launching program or script. besides, increasing finite max not rid of issue.

i rewrite of code persist objects file system (using database same thing) free memory. work, it's lot work too.

if point me details of above ideas or alternatives automatic virtual memory, extending heap size dynamically, great.

ultimately have finite max of heap use no matter platform running on. in windows 32 bit around 2gb (not heap total amount of memory per process). happens java chooses make default smaller (presumably programmer can't create programs have runaway memory allocation without running problem , having examine doing).

so given there several approaches take either determine amount of memory need or reduce amount of memory using. 1 common mistake garbage collected languages such java or c# keep around references objects no longer using, or allocating many objects when reuse them instead. long objects have reference them continue use heap space garbage collector not delete them.

in case can use java memory profiler determine methods in program allocating large number of objects , determine if there way make sure no longer referenced, or not allocate them in first place. 1 option have used in past "jmp" http://www.khelekore.org/jmp/.

if determine allocating these objects reason , need keep around references (depending on doing might case), need increase max heap size when start program. however, once memory profiling , understand how objects getting allocated should have better idea how memory need.

in general if can't guarantee program run in finite amount of memory (perhaps depending on input size) run problem. after exhausting of need caching objects out disk etc. @ point should have reason "i need xgb of memory" , can't work around improving algorithms or memory allocation patterns. case algorithms operating on large datasets (like database or scientific analysis program) , techniques caching , memory mapped io become useful.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -