Solved

The  toString()  method

Posted on 2000-05-08
8
448 Views
Last Modified: 2013-11-23
I'm using the class CharArrayWriter
and in the buffer i have more then 1 megabyte of data , the problem is that
when using the toString() method my application is crashing with the following error :

Exception in thread "main" java.lang.OutOfMemoryError
        at java.io.CharArrayWriter.write(CharArrayWriter.java, Compiled Code)
        at java.io.Writer.write(Writer.java, Compiled Code)
        at org.apache.ecs.ConcreteElement.output(ConcreteElement.java, Compiled
Code)

is there a limit to the toSting method ?

0
Comment
Question by:yossim111799
8 Comments
 

Expert Comment

by:diegojimenez
ID: 2787476
No, I think that the problem is from your pc. In the API says: "The buffer size may be specified, or the default size may be accepted. The default is large enough for most purposes".
0
 
LVL 3

Expert Comment

by:rjackman
ID: 2787478
this exception is
Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.


try changing ur virtual memory size to higher than 1 mb for that u should take care that u are having that much of free space on the hard drive
or the other option is to print the  object part by part instead of printing entire object at a time u can do like this
0
 

Expert Comment

by:ytgprasad
ID: 2787545
There is no size limit on the toSting method. Try running ur program closing some application and try after increasing ur virtual memory size also.
0
 
LVL 3

Expert Comment

by:rjackman
ID: 2787678
hey ytgprasad  what about my comment first....?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:ytgprasad
ID: 2787863
ytgprasad changed the proposed answer to a comment
0
 

Author Comment

by:yossim111799
ID: 2787989
O.K
And what needs to be done when running
the java application on unix HP machine
how can i change the virtual memory size ?
0
 
LVL 7

Accepted Solution

by:
vladi21 earned 200 total points
ID: 2788199
Which JRE do you use?

look

http://www.codeguru.com/java/articles/513.shtml

By default, the JVM will use up to 16Mb of RAM. If your program allocates a lot of memory, you may need to increase this value to give more room to the garbage collector.

When starting the JVM, two parameters can be adjusted to suit your memory needs :

-mx n
Sets the maximum size of the memory allocation pool where n is in bytes, appending "m" to n will specified the number in megabytes, for example to set the maximum at 20Mb :


 java -mx 20m myApp

-ms n
Sets the startup size of the memory allocation pool, where n is in bytes, appending "m" to n will specified the number in megabytes. The default is 1Mb.



1.2
java -Xms64M -Xmx128M programname


Java memory management
http://www.javaworld.com/javaworld/javaqa/1999-08/04-qa-leaks.html
www.optimizeit.com
JProbe from KLGroup  www.klgroup.com


Java Tip 79: Interact with garbage collector to avoid memory leaks
http://www.javaworld.com/javaworld/javatips/jw-javatip79.html

How can I calculate the minimum amount of memory needed to run my application?
http://developer.java.sun.com/developer/qow/archive/27/index.html

0
 
LVL 5

Expert Comment

by:mbormann
ID: 2788477
anoter thing is that if u no that ur buffer is going to be 1Meg preallocate it by specifying it during construction,this means that it won't have to realloc EACH time buffer exceeds the current value and also control by how fast the allocation goes i.e in how many bytes.

This means that you are allocating only once whereas if u dont follow this method u allocate many times

Cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now