What is the difference between these statements
obj=null and obj.dispose()
Answers were Sorted based on User's Feedback
Answer / sanjeev
obj=null
when we use obj=null then this object has existence in
memory with no any value.
obj.dispose()
when we use obj.dispose() then the clr release the memory
and there are no any existence of that object into the
memory. so it will be better to use obj.dispose()
Note:- By default it is automatically disposed by the clr
when there are no any references in the left
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / pushparaj pentakota
obj=null is remove the reference to object only but that
object will be existed but obj.dispose() is clear the
reference and as well as clear the object also from the
memory.so obj.dispose() is best to use but in some cases not.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / dhinaharan
obj.dispose has to be used and not obj=null, bcoz JIT
compiler is optimizing compiler, and setting a local
variable or parameter to null is the same as not
referencing the variable at all.
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / kishoreg
This is not a good and safe practice to call a Dispose.
In "Dot Net" it is automatically handle by Garbage
collection. It is the responsibility of GC to call the
Dispose and clear the memory.. but it is not sure that when
GC will call the Dispose.
so in that case we can forcefuly call it.
Consider one case when we forcefully destroy the object and
after some time i will try to use the same object at that
time u will get the error msg.
so better to object = null;
other material:
http://blogs.msdn.com/irenak/archive/2006/10/05/SYSK-
212_3A00_--Does-.NET-Garbage-Collector-call-Dispose_3F00_--
Dispose-_1320_-Best-Practices_2E00_.aspx
Is This Answer Correct ? | 4 Yes | 4 No |
HOW to Develope the CRUD(create,read,update,delete) FORM IN WINDOWS form by using c# only
0 Answers Petranics Solutions,
What is difference between abstraction and encapsulation in c#?
Why do we need singleton class in c#?
What exactly happens when we debug and build the program?
What is asax file in c#?
public void A() { int x; x = 8; x *= 4 + 8 / 2; } Given the above code, what is the value of "x"?
destructor, Dispose, Finalize - How they relate to each other
Explain About DTS package
What is the lock statement in c#?
Does c# support parameterized properties?
What is static class in C#?
How you will connect to windows directory in c#?
2 Answers HP, nTech Solutions,