A question about possible memory leakage using RMI
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Wei_Qian
Posted On:   Thursday, May 27, 2004 07:41 PM

I am using RMI to develop a client/server program. Since the client needs the data from the server, I designed a method on server like below: public Vector listTestflow(int prjID) { Vector v = new Vector(); ... //Processing the result set retrieved from database //Added to vector return v; } Then the client invoke the remote method "listTestflow", and get the returned vector "v". After client finished using this vector "v", it will set "v = null". So my idea is that the vector reference in client is already set to null, but how about the real object "v" in the RMI server? Do I need to set the "v" in server    More>>

I am using RMI to develop a client/server program. Since the client needs the data from the server, I designed a method on server like below:
public Vector listTestflow(int prjID)
{
Vector v = new Vector();
...
//Processing the result set retrieved from database
//Added to vector
return v;
}

Then the client invoke the remote method "listTestflow", and
get the returned vector "v".
After client finished using this vector "v", it will set
"v = null". So my idea is that the vector reference in client is already set to null, but how about the real object "v" in the RMI server? Do I need to set the "v" in server to null also? I think if I don't set the object "v" in server to null, it will cause the memory leakage. Am I correct?

   <<Less

Re: A question about possible memory leakage using RMI

Posted By:   Sean_Owen  
Posted On:   Friday, May 28, 2004 07:58 AM

The client and server are on different machines, so there are two entirely different JVMs and Vector objects here.



On the server, a Vector is created in this method. When the method listTestFlow() finishes on the server, there will no longer be a reference to this Vector in the server's JVM, so it will eventually be garbage collected, just like anything else. There is no need to null the reference.



RMI, on the client side, constructs a new Vector just like the one on the server, from the data it receives across the network. Again, this Vector lives as long as there are references to it, and will be GC'ed eventually once there are no more. Nothing special there.



Just realize that the client's copy of the Vector, and client's references, are completely independent of those on the server.

About | Sitemap | Contact