|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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; } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Memory leak |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|