Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #617
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail |
|---|---|
| From | "cakmak" <cakmak@THRWHITE.remove-dii-this> |
| Subject | Re: Memory Leak in swing |
| Message-ID | <1168423839.306143.47480@77g2000hsv.googlegroups.com> (permalink) |
| X-Comment-To | comp.lang.java.gui |
| Newsgroups | comp.lang.java.gui |
| In-Reply-To | <eo14u90ph4@news2.newsguy.com> |
| References | <eo14u90ph4@news2.newsguy.com> |
| Content-Type | text/plain; charset=IBM437 |
| Content-Transfer-Encoding | 8bit |
| X-Gateway | time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] |
| Lines | 121 |
| Date | Wed, 27 Apr 2011 15:28:34 GMT |
| NNTP-Posting-Host | 96.60.20.240 |
| X-Complaints-To | news@tds.net |
| X-Trace | newsreading01.news.tds.net 1303918114 96.60.20.240 (Wed, 27 Apr 2011 10:28:34 CDT) |
| NNTP-Posting-Date | Wed, 27 Apr 2011 10:28:34 CDT |
| Organization | TDS.net |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.gui:617 |
Show key headers only | View raw
To: comp.lang.java.gui
I stripped-down my code, this also gathers surviving objects.
Application containing this code could not live long. (A thread wait of
1 sec. also does not help.) sorry for the long posting, but it is
really despairing!
public class LeakCheck {
private int counter=0;
private final String randomquery = "SELECT TOP 4 T00801PersonNr AS
PersonNr, T00801PersonID AS PersonID, T00801Nachname AS
Nachname, T00801Vorname AS Vorname FROM DBA.T00801Person ORDER BY
RAND()";
private class Person extends Object {
private javax.swing.ImageIcon icon;
private String number;
protected void finalize() throws Throwable {
if(icon!=null){
icon.getImage().flush();
icon = null;
}
super.finalize();
}
}
private ArrayList<Person> personList = new ArrayList<Person>();
protected class RefreshTask extends TimerTask {
@Override
public void run() {
random();
}
}
public void go(){
Timer updateTimer = new Timer("Refresh Task");
updateTimer.schedule(new
RefreshTask(),0,2000);//instance,delay,interval
}
private Image LoadImageFromDB(String personnr){
Image img = null;
String filename = personnr + ".jpg";
Connection con =
DbInterface.getinstance().getEtrainerDBConnection();
Statement stmt;
ResultSet rs;
try {
stmt = con.createStatement();
String query =
Resources.getInstance().getDbProperties().getProperty("selectPersonImage");
query = String.format(query, filename);
rs=stmt.executeQuery(query);
if(rs.next()){
int len=rs.getInt(2);
byte [] b=new byte[len];
InputStream in = rs.getBinaryStream(3);
try {
in.read(b);
in.close();
img=Toolkit.getDefaultToolkit().createImage(b);
} catch (IOException e) {
e.printStackTrace();
}
}
rs.close();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
return img;
}
public void random(){
java.sql.Connection con =
DbInterface.getinstance().getSybaseDBConnection();
try {
if(con!=null && !con.isClosed()){
java.sql.Statement stmt=null;
try {
stmt = con.createStatement();
java.sql.ResultSet rs =
stmt.executeQuery(randomquery);
while(rs.next()){
Person person = new Person();
person.number = rs.getString("PersonNr");
Image img = LoadImageFromDB(person.number);
if(img !=null){
ImageIcon ico = new ImageIcon(img);
person.icon = ico;
}
personList.add(person);
System.out.println("Container size: " +
personList.size());
counter++;
}
if(counter%20 == 0){
personList.clear();
System.gc();//no need, but I force for this
example
System.out.println("Container cleared, size: "
+ personList.size());
}
rs.close();
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
LeakCheck leakCheck = new LeakCheck();
leakCheck.go();
}
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar
Memory Leak in swing appl "cakmak" <cakmak@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "cakmak" <cakmak@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "cakmak" <cakmak@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "cakmak" <cakmak@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "steve" <steve@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "cakmak" <cakmak@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "steve" <steve@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
Re: Memory Leak in swing "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:28 +0000
csiph-web