Solved

The  toString()  method

Posted on 2000-05-08
8
447 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

743 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

12 Experts available now in Live!

Get 1:1 Help Now