Hey sorry I wrote it wrong in a hurry:
U r right, that we need not make it null since the stack unstacks the
objects whenever we exists.But there is one thing that I learnt yesterday
that when we pass objects to a method they are NOT passed by reference,
Instead the "reference is passed by value".I''ll explain you what I mean.
Example:
Void method1()
{
Method2(object obj1);
}
Void metod2(object obj2)
{
}
What actually has happened is
Stack | Heap
Obj1 --------->| |
Obj2 --------->|_____|
That is both the objects are actually pointing to the same type and hence
the values get changed but actually the reference is copied to another
instance....
Warm Regards,
Mili Aggarwal
----------------------------------------------------------------------------
-----------------------------DISCLAIMER-------------------------------------
----------------------------------------------------------------------------
--------
This message and any attachment contained here are information that is
confidential, proprietary to HCL Technologies and its customers. Contents
may be privileged or otherwise protected by law. The information is solely
intended for the individual or the entity it is addressed to. If you are not
the intended recipient of this message, you are not authorized to read,
forward, print, retain, copy or disseminate this message or any part of it.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 12:52 PM
To: [email protected]
Subject: RE: out of memory.
Hey Mili, thanks for the tips. We Java programmers get lazy at times thanks
to the garbage collector and forget that there actually some things we need
to take care of ourselves (like closing files and database connections and
statements).
Your second tip doesn't seem to make sense though:
> 2) If passing an object to a method, make sure you assign the
> object=null
> once you are through with the method. It wont affect the
> original object as
> in Java objects are not passed by reference...
The parameters passed to a method are stored on the stack. They are removed
when the method exits (since the stack frame for the method is then cleaned
up). So setting the reference to null right before exiting the method really
has no effect. And just to clarify: Java objects _are_ passed by reference.
However, the arguments to a method are passed by value. For objects, the
argument is an object _reference_, so the reference is passed by value and
changing it in the method will not change the reference in the calling
method.
If POI really writes 65000 rows to file, that might be worth fixing in
CVS... Any POI developers on this list that can comment?
Regards,
Frans
> -----Original Message-----
> From: Mili Aggarwal, Noida [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 08, 2005 6:29 AM
> To: POI Users List
> Subject: RE: out of memory.
>
>
> Hey Vyom,Thanks for the help I sorted it out...Actually the memory was
> leaking due t non-closure of a prepared Statement but there
> are some GREAT
> Java lessons that I learnt which I thought I must share with you guys:
>
>
>
> 1) Whenever coding that requires DB connectivity do remember
> do double check
> that all your DBConnections,PreparedStatements,ResultSet are properly
> closed.
>
> 2) If passing an object to a method, make sure you assign the
> object=null
> once you are through with the method. It wont affect the
> original object as
> in Java objects are not passed by reference...
>
>
>
> I know it's a POI forum but I thought why not share some Java
> intricacies.
>
>
>
> 3) I came across a tool that detects memory leak and tells
> what all objects
> are present in memory. It can really help someone to optimize
> the code. It
> comes with BEA's Jrockit. Try it out. Its awesome.
>
>
>
> http://e-docs.bea.com/wljrockit/docs142/userguide/memleak.html
> <http://e-docs.bea.com/wljrockit/docs142/userguide/memleak.html>
>
>
>
> (I am not working for BEA ;-) )
>
>
>
> 4) Another article of interest that I came up with is:
>
<<cut>>
-----------------------------------------------------------------
ATTENTION:
The information in this electronic mail message is private and
confidential, and only intended for the addressee. Should you
receive this message by mistake, you are hereby notified that
any disclosure, reproduction, distribution or use of this
message is strictly prohibited. Please inform the sender by
reply transmission and delete the message without copying or
opening it.
Messages and attachments are scanned for all viruses known.
If this message contains password-protected attachments, the
files have NOT been scanned for viruses by the ING mail domain.
Always scan attachments before opening them.
-----------------------------------------------------------------
Disclaimer:
This message and any attachment(s) contained here are information that is
confidential,proprietary to HCL Technologies and its customers, privileged
or otherwise protected by law.The information is solely intended for the
individual or the entity it is addressed to. If you are not the intended
recipient of this message, you are not authorized to read, forward,
print,retain, copy or disseminate this message or any part of it. If you
have received this e-mail in error, please notify the sender immediately by
return e-mail and delete it from your computer.