• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you dont require the "<" and ">"

eg:

-Xmx1024M
 
Marshal
Posts: 79816
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult for Beginning Java. Moving.

Santosh Raveendran's first point looks very useful. Have you tried that?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic