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
Solved

The  toString()  method

Posted on 2000-05-08
8
450 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java exception bubble up 2 21
ejb entity bean example 2 10
Java syntax, or is it Selenium 6 30
Selenium docs api java index 3 48
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 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