File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to set free my heaped memory ? after java.lang.OutOfMemoryError: Java heap space Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to set free my heaped memory ? after java.lang.OutOfMemoryError: Java heap space" Watch "how to set free my heaped memory ? after java.lang.OutOfMemoryError: Java heap space" New topic
Author

how to set free my heaped memory ? after java.lang.OutOfMemoryError: Java heap space

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Hi
I have faced a problem, when I run my project it goes well for some seconds and after it throws me an error:

...

as I find I did it by using many loops or "for"s or I may not close my DB statement. being honest I didnt close my DB statements, which I do it now.
But its still giving me that error!
I think I need to set that memory free, but how? can you elaborate on it for me? or introduce me a source.
Thank you,
Sahar.
Santosh Raveendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 83

as first step revisit your code to avoid any unwanted memory leaks and if we dont have any leaks proceed with increasing the jvm heap size which will

fix your issue.

use the below command line options


1 -Xms<size> set initial Java heap size

2 -Xmx<size> set maximum Java heap size


SCJP 1.4,SCWCD5, SCBCD5
Thanks, Santhosh
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
excuse me, But I am really new in this one! may it seems a little stupid!
but let me explain step by step, what you mean is :
1)I need to go to command promp
2) then write "Xms<256m>" for example. right?
but it says: the syntax of the command is incorrect!!
Also,I found a program who tells me how much memory heap I have now, which returns me:
Heap Size = 5177344
I read 256m is for small program like "hellow world" but mine is rather bigger project(including DBs and agents) but I dont know how much memory I need ?

sorry for many questions and thanks,
Sahar
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

I believe you dont require the "<" and ">"

eg:

-Xmx1024M


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38844
    
  23
Too difficult for Beginning Java. Moving.

Santosh Raveendran's first point looks very useful. Have you tried that?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11313
    
  16

to be clear...

you don't type the -Xmx1024M by itself on the command line, but as part of your java call:


c:\>java -Xmx1024M -Xms1024M MyClass

Note that this doesn't necessarily FIX your problem, it might just be hiding it. If your code is not releasing things it should, you may still have the same problem at some point but you're just not hitting the limit yet.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Sahar:

The JConsole tool, which comes with the JDK, can help you profile your program's memory usage.

John.
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Hi guys,
I find how to track this leaking points or to make sure where they are coming from (from JDBC connections? or generating Many objects ? or your program really needs a big heap memory to run! and there is nothing wrong with the program).

1) to find in which part of code (or thread) it starts to eat memory use this link to download YourKit java profil:
http://www.yourkit.com/download/index.jsp
(I have tried many software but this is the best: 0) its free! 1) starts outomatically you just need to download it! 2) has a very rich documentation you can have look at: http://www.yourkit.com/docs/80/help/memory_telemetry.jsp )

2)to make sure if it is from your connections or something else, (if you are using mySQL) download mysql-gui-tool from :
http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0-r17-win32.msi/from/pick?file=Downloads/MySQLGUITools/mysql-gui-tools-5.0-r17-win32.msi&mirror=pick&file=Downloads/MySQLGUITools/mysql-gui-tools-5.0-r17-win32.msi&mirror=pick#mirrors
this will help you to see how many connections you have at the time. what you need is to make a connection to your data base in MSQL ADMINISTRATOR. and then go to server connections. now go to your IDE and run your Java program. while running you can see how many connections you have in the TREAD tab of your "server connections" in MSQL ADMINISTRATOR.

So if there are normal amount of connections its not JDBC connections which are consuming the memory!

3) If you think nothings wrong with your code and it just nedd more memory there are two ways to change the setting: 1) Command prompt and 2) your IDE. I Killed my self but couldnt do it by command way .
IDE way is sooo easy just go to netbeans click right on the project name > properties>run and then in "VM options" text box copy "-Xms32m -Xmx128m" and its done!!

and thats all I experienced!
If any one have any other suggestion is welcomed!
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
hey guys,
some use full links about rrors on initializing heap size:
errors on JAVA heap memory
how to initialize java heap memory

cheers
Sahar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set free my heaped memory ? after java.lang.OutOfMemoryError: Java heap space