Solved

The  toString()  method

Posted on 2000-05-08
8
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:rjackman
ID: 2787678
hey ytgprasad  what about my comment first....?
0
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android development question 2 76
pagenation logic how it is working in my code 1 69
jsp error 6 43
How to log java errors in tomcat 8 24
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

740 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