Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2007, 08:02 AM
Member
 
Join Date: Nov 2007
Posts: 3
DonnieDarko is on a distinguished road
problem with Java Vm options
Hi, I am trying to compile this program to check for memory leaks.

************************************************** Main.java***************************************** **********8
import java.util.EmptyStackException;
public class Main {
static final int MAX_ELEMENTS = 25;
Object[] elements = new Object[MAX_ELEMENTS];
int size = 0;

public void push(Object o) {
elements[size++] = o;
}
public Object pop() {
if (size == 0)
{System.out.println("size is 0");return null;}

else {
Object result = elements[--size];
/* elements[size] = null; */
return result;
}
}
public static void main(String[] args) {
Main stackLeaker=new Main();
Object bigObj = null;
try {
//populating the stack
for (int i = 0; i < MAX_ELEMENTS; i++) {
bigObj = new BigObject();
System.out.println("created object no: "+(i+1));
stackLeaker.push(bigObj);
/*stackLeaker.push(new
WeakReference<BigObject>(bigObj));*/
}
//accessing the stack
for (int i = 0; i < MAX_ELEMENTS; i++) {
stackLeaker.pop();
}
//creating an extra object
Object big2 = new BigObject();

}
catch (OutOfMemoryError e) {

e.printStackTrace();
}
}
}

************************************************** ***********BigObject.java************************* *******
public class BigObject {
static final int SIZE = 10000000;
int[] numbers = null;
public BigObject() {
numbers = new int[SIZE];
}
}
************************************************** ************************************************** *************

like this :
java -Xms256m -Xmx256m Main

and I get the following output:
created object no: 1
created object no: 2
created object no: 3
created object no: 4
created object no: 5
java.lang.OutOfMemoryError: Java heap space
at BigObject.<init>(BigObject.java:5)
at Main.main(Main.java:26)

As you can see in BigObject.java that the size of BigObject is 10 Mb . Now my problem is that why does the program indicate OutofMemoryError after making just 5 objects when the heap size is 256 mb. I even tried using netbeans profiler and noted that the application was throwing this xception even when the used heap size was way less than max heap size. Where am I going wrong?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-21-2007, 05:22 PM
Member
 
Join Date: Nov 2007
Posts: 3
DonnieDarko is on a distinguished road
Edit: Sorry my bad.
The bigObject is not 10 mb in size
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening frame/page options Java Tip Java Tips 0 03-10-2008 04:50 PM
JOptionPane - showConfirmDialog(...) options Java Tip Java Tips 0 12-17-2007 11:38 AM
ComboBox with database options Goldy Advanced Java 0 12-01-2007 11:43 PM
How to set General options in NetBeans IDE JavaForums NetBeans 0 08-02-2007 02:11 PM
java SE 6 problem techlance Java Applets 1 06-28-2007 12:10 PM


All times are GMT +3. The time now is 10:18 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org