Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old October 22nd, 2001, 03:47 PM
rgarabedian rgarabedian is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 4 rgarabedian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Memory leak

So I have this simple java server. Works great .. until I notice it gobbles up memory with every request. After some initial investigation, it appear as though the classes that serve as the threads I spin off to service the request are not being reclaimed. I'm having trouble determining what is going on, so I wrote a simple base case (code listed below). When I run this, and connect to the server multiple times via telnet, I never see the output from the garb2's finalize method. I'm assuming this is because the class is never marked for garbage collection. How come? I must be missing something incredibly obvious here ...

public class Garb1
{
public static void main(String[] args)
{
try
{
ServerSocket sc = new ServerSocket(9090);
sc.setSoTimeout(30000);

while(true)
{
try
{
Socket sock = sc.accept();
System.out.println("Incomming connection received");
Garb2 wt = new Garb2(sock);
wt.run();

System.out.println("Run() called, looping around");
}
catch(java.io.InterruptedIOException joi)
{
System.out.println("Interrupted exception caught");
}
}
}
catch(Exception e)
{
System.out.println("Error");
}
}
}


public class Garb2 extends Thread
{
public Garb2(Socket p_socket)
{
System.out.println("Garb2 constructing");
_buffer = new int[90000];
_socket = p_socket;
setName("Garb2");
}

public void run()
{
System.out.println("Garb2 running. Closing socket ...");
try
{
_socket.close();
}
catch(Exception e)
{
System.out.println("Error closing socket");
}
System.out.println("Garb2 exiting");
}

public void finalize () throws java.lang.Throwable
{
System.out.println("Garb2 finalize method called");
}

private Socket _socket;
int[] _buffer;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Memory leak


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway