Using string buffer without selecting the proper construction can lead to memory leak.
Lets have a look of the constructor of string buffer
Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
public StringBuffer() {
super(16);
}
Suppose you are creating objects of type StringBuffer in a loop, no of objects may change depnding upon the input. Every time it will create object to store at least 16 characters, you may not need all the 16, in that case remaining space will be unused and cannout be allocated for other purpose.
At some point these unused memory location may lead to Out of memory problem.
Instead of that we can use another constructor
Constructs a string buffer with no characters in it and the specified initial capacity.
public StringBuffer(int capacity) {
super(capacity);
}
Subscribe to:
Post Comments (Atom)
Heroku Custom Trust Store for SSL Handshake
Working with Heroku for deploying apps (java, nodejs, etc..) is made very easy but while integrating one of the service ho...
-
Multi-Tenancy with the SaaS based model does not bring any change on the application layer as multiple services deployment of application w...
-
I have a class which is not serializable. If i will try to serialize the object of it than i am going to get exception "java.io.NotSer...
-
Raspberry Pi is an awesome and interesting . I was totally astonished after knowing about it from one of my friend and colleague "Ale...
Nice brief and this enter helped me alot in my college assignement. Thanks you for your information.
ReplyDeleteWell your article helped me very much in my college assignment. Hats off to you send, wish look progressive for more cognate articles without delay as its sole of my favourite issue to read.
ReplyDeleteSorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.
ReplyDelete