Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

The  toString()  method

Posted on 2000-05-08
8
Medium Priority
?
456 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
Technology Partners: 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 800 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

610 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