File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sahar sa
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
sahar sa
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 1227
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you dont require the "<" and ">"

eg:

-Xmx1024M
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult for Beginning Java. Moving.

Santosh Raveendran's first point looks very useful. Have you tried that?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sahar:

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

John.
 
sahar sa
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic