This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Memory Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Memory Problem " Watch "Memory Problem " New topic
Author

Memory Problem

Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi All..

I have question about the memory size taken by the java process.

We had delivered two iterations IT1 and IT2 ,

IT1 when runs it consumes only 15 MB , BUt IT2 (obviously code is more )
consumes 45MB of RAM .

The difference is huge, do you know if some compilation options can affect the memory size taken by clients appln.

Is there any way that we set some compliation arg so that memory consumtion by the IT2 takes less than 45MB

Thanks in Advance


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
I am not clear about your requirements.

Do you means to say you have run two iteration of same program � first time it occupy 15 MB and second time 45 MB?


My blood is tested +ve for Java.
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Basic question i have 1 iterations code 2nd iteration code is bit more in size ...
when we run appln with ietration 1 code in memory it javaw.exe takes less MB
2nd iteration code takes more memory (javaw.exe takes more MB) than the iteration 1 's code
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

yes second iteration code is more and new programmers have coded them , hence when running the appln javaw.exe is taking so much of memory
than prior iteration code apart from increasing heap memory size in complier options do we have any options
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

How much memory a program needs, depends on what the program does; how many objects it allocates etc.

Since you didn't tell us anything about what your program does and what exactly the differences are in the code, it is impossible to give you a precise anwer.

It's easy to write a 5-line program that uses a lot of memory. The memory usage doesn't have anything to do with the size of the source code.

You'll just have to go and look at the code, or maybe use a profiler, to see why the program uses so much more memory. (A profiler is a tool that measures the execution speed and memory usage of a program while it's running).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
apart from increasing heap memory size in complier options do we have any options


There is no magic wand you can wave and get lower memory use. More code means more objects so more runtime memory will be required.
Why are you talking about compiler options? It is runtime options that affect memory use.
Bill
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
How are you measuring "memory use"?

I just wonder because, if you are using Windows Task Manager to do it, there is a common trap that people fall into. The Windows Task Manager column "Memory Usage" is the amount of *physical* memory used. This is not a particularly useful figure, as the Java classes and heap are in *virtual* memory. You need to look at the "VM Size" column, which is not shown in Task Manager by default, but can be added from the menu.

If you're not using Windows, or you've not made this mistake, please accept my apologies for the suggestion.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

Originally posted by William Brogden:

Why are you talking about compiler options? It is runtime options that affect memory use.
Bill


The -g:none option of javac removes debugging information which results in smaller classes. Smaller classes means less memory displaced when loaded:

I'd think that classes aren't the bulk of memory use in any non-trivial program (object instances, especially Strings would be) so this optimization would probably have little practical effect.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi Friends Thanks for your valuable replies...
later after investigating i came to know that our framework intialises the facade and Dao factory ...
as code increases i.e ( adding couple of mtds in DAO) i think it is obvious that it will takle more memory .
Is there any Runtime GC code which i can run to avoid to decrease the memory consuption will which i will run frequently
Any Idea will this work out ?.

Thanks in Advance
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
There are some cool tools for watching memory use. With Java5 or later you get JConsole. You can watch the various areas of memory go up and then GC. It's not a problem to see usage go near the max between GCs. It is probably a problem to see the low end of the sawtooth graph go up and up all day.

One of our guys uses an IBM tool that reads verbose GC logs and spits out a report of large object creation (over a configured threshold). That helped us find a class that was trying to log a 10meg string (!). It never got to the log because the switch was turned off for that class, but it got through message formatting which made multiple copies of the data.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Exactly what are you worried about?

Is there some sort of hard limit to the amount of memory this app is allowed to use or is this just generalized worry about memory use getting out of control?

In any case, it is not GC code you should be looking for but memory management techniques and best practice. Let Java take care of GC for you.

You might want to take a look at the java.lang.ref package of classes for flexible object management.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory Problem
 
Similar Threads
Help - Application crash.
question on arrays?
SCJP Generics(problem with under standing)
Simple ArrayList conundrum?
Why two interfaces ( home and component ) ?