Subject | RE: [Firebird-Java] Re: Possible memory leak in EncodingFactory ? |
---|---|
Author | Rick Debay |
Post date | 2006-06-15T14:32:39Z |
Here is the code you are writing about:
No chance of a leak in this code, unless String.getBytes() allocates off
of the heap and your garbage collection thread is falling behind.
public byte[] encodeToCharset(String in){
byte[] result = null;
try {
result = in.getBytes(encoding);
}
catch (UnsupportedEncodingException uee){
}
return result;
}
If the garbage collection thread falls behind, the new String() may
cause heap memory to grow.
public int encodeToCharset(char[] in, int off, int len, byte[] out){
byte[] by = null;
try {
by = new String(in).getBytes(encoding);
System.arraycopy(by, 0, out, 0, by.length);
}
catch (UnsupportedEncodingException uee){
}
return by.length;
}
If caching is ever implemented, the equals() and hash() methods could be
added to Encoding_NotOneByte and a new one would not need to be
generated every time a column needs to be encoded or decoded. I'd also
make the encoding final and add a getEncoding() method just because I'm
anal about stuff like that. However, it would only reduce your problem
slightly as the member variable that contains the charset name is very
small compared to the text you're encoding.
What charset are you encoding from/to? Is it a multi-byte character
set?
BTW, does anyone know how Jaybird is supposed to behave if an
UnsupportedEncodingException occurs? As far as I can tell, it'll
silently send an empty buffer to the database.
Rick DeBay
-----Original Message-----
From: Firebird-Java@yahoogroups.com
[mailto:Firebird-Java@yahoogroups.com] On Behalf Of Mathew Joseph
Sent: Thursday, June 15, 2006 12:36 AM
To: Firebird-Java@yahoogroups.com
Subject: [Firebird-Java] Re: Possible memory leak in EncodingFactory ?
Hi There,
I have been writing a program to read mails and store the content into
a firebird database. It consumes a large amount of heap memory and the
tool that i am using shows me memory leak problems with the
Encoding_NotOnebyte.encodeTocharset function. I came across this
response from you and was wondering whether you have put changes into
the CVS regarding this problem.
Regds
Mathew
No chance of a leak in this code, unless String.getBytes() allocates off
of the heap and your garbage collection thread is falling behind.
public byte[] encodeToCharset(String in){
byte[] result = null;
try {
result = in.getBytes(encoding);
}
catch (UnsupportedEncodingException uee){
}
return result;
}
If the garbage collection thread falls behind, the new String() may
cause heap memory to grow.
public int encodeToCharset(char[] in, int off, int len, byte[] out){
byte[] by = null;
try {
by = new String(in).getBytes(encoding);
System.arraycopy(by, 0, out, 0, by.length);
}
catch (UnsupportedEncodingException uee){
}
return by.length;
}
If caching is ever implemented, the equals() and hash() methods could be
added to Encoding_NotOneByte and a new one would not need to be
generated every time a column needs to be encoded or decoded. I'd also
make the encoding final and add a getEncoding() method just because I'm
anal about stuff like that. However, it would only reduce your problem
slightly as the member variable that contains the charset name is very
small compared to the text you're encoding.
What charset are you encoding from/to? Is it a multi-byte character
set?
BTW, does anyone know how Jaybird is supposed to behave if an
UnsupportedEncodingException occurs? As far as I can tell, it'll
silently send an empty buffer to the database.
Rick DeBay
-----Original Message-----
From: Firebird-Java@yahoogroups.com
[mailto:Firebird-Java@yahoogroups.com] On Behalf Of Mathew Joseph
Sent: Thursday, June 15, 2006 12:36 AM
To: Firebird-Java@yahoogroups.com
Subject: [Firebird-Java] Re: Possible memory leak in EncodingFactory ?
Hi There,
I have been writing a program to read mails and store the content into
a firebird database. It consumes a large amount of heap memory and the
tool that i am using shows me memory leak problems with the
Encoding_NotOnebyte.encodeTocharset function. I came across this
response from you and was wondering whether you have put changes into
the CVS regarding this problem.
Regds
Mathew