Click here to Skip to main content
15,894,410 members
Home / Discussions / C#
   

C#

 
AnswerRe: Want to retrieve memory details Pin
originSH30-Jul-07 3:29
originSH30-Jul-07 3:29 
QuestionDispose Method Pin
N a v a n e e t h30-Jul-07 2:45
N a v a n e e t h30-Jul-07 2:45 
AnswerRe: Dispose Method Pin
Martin#30-Jul-07 2:51
Martin#30-Jul-07 2:51 
GeneralRe: Dispose Method Pin
N a v a n e e t h30-Jul-07 2:56
N a v a n e e t h30-Jul-07 2:56 
GeneralRe: Dispose Method Pin
originSH30-Jul-07 2:59
originSH30-Jul-07 2:59 
AnswerRe: Dispose Method Pin
Luc Pattyn30-Jul-07 3:06
sitebuilderLuc Pattyn30-Jul-07 3:06 
GeneralRe: Dispose Method Pin
Guffa30-Jul-07 4:12
Guffa30-Jul-07 4:12 
GeneralRe: Dispose Method Pin
Luc Pattyn30-Jul-07 4:50
sitebuilderLuc Pattyn30-Jul-07 4:50 
Hi Guffa,


Guffa wrote:
ObjectWithHugeArray obj = new ObjectWithHugeArray();
obj.GetSomeData();obj.DisplayTheData();
// the memory is collectable here already
GetSomeUserInput();
obj = null;


I think I don't agree in general and with the // comment in particular.

I assume you intend the example to be the code of a single method, with obj
a class member, not a local variable.

(if it were a local variable, setting it to null with no statements following
that use it's value, the "obj=null;" statement would be chopped out
by the optimizer).

Not having an obj.Dispose(); ends the life of the obj value sooner when
looking at the code in the method itself; IMO that on its own is insufficient to
expect the compiler to move "obj=null;" upwards. And it is not allowed to move
it over the GetSomeUserInput() method call, without making sure the value of obj
isnt used in there.

So I expect the obj variable be present on the stack, and be cleared only
after returning from the Input method; hence the GC would find the hugeobject
reference, and would have to keep it alive (together with its huge array, for
which my Dispose() would have removed the only reference).

So I don't see how your example works in substatntiating your statement
that Dispose() could work adversely, which I still don't see possible.

Smile | :)









GeneralRe: Dispose Method [modified] Pin
Martin#30-Jul-07 5:20
Martin#30-Jul-07 5:20 
GeneralRe: Dispose Method Pin
Luc Pattyn30-Jul-07 6:26
sitebuilderLuc Pattyn30-Jul-07 6:26 
GeneralRe: Dispose Method Pin
Luc Pattyn13-Aug-07 1:53
sitebuilderLuc Pattyn13-Aug-07 1:53 
GeneralRe: Dispose Method Pin
Martin#13-Aug-07 2:15
Martin#13-Aug-07 2:15 
GeneralRe: Dispose Method Pin
Guffa30-Jul-07 22:09
Guffa30-Jul-07 22:09 
GeneralRe: Dispose Method Pin
Luc Pattyn30-Jul-07 22:49
sitebuilderLuc Pattyn30-Jul-07 22:49 
GeneralRe: Dispose Method Pin
Guffa2-Aug-07 7:47
Guffa2-Aug-07 7:47 
GeneralRe: Dispose Method Pin
Luc Pattyn2-Aug-07 8:23
sitebuilderLuc Pattyn2-Aug-07 8:23 
GeneralRe: Dispose Method Pin
Guffa4-Aug-07 1:08
Guffa4-Aug-07 1:08 
GeneralRe: Dispose Method [modified] Pin
Luc Pattyn4-Aug-07 14:48
sitebuilderLuc Pattyn4-Aug-07 14:48 
GeneralRe: Dispose Method Pin
Luc Pattyn2-Aug-07 21:56
sitebuilderLuc Pattyn2-Aug-07 21:56 
GeneralRe: Dispose Method Pin
Guffa4-Aug-07 1:19
Guffa4-Aug-07 1:19 
AnswerRe: Dispose Method Pin
Karthi_jpk30-Jul-07 3:19
Karthi_jpk30-Jul-07 3:19 
AnswerRe: Dispose Method Pin
Scott Dorman31-Jul-07 14:29
professionalScott Dorman31-Jul-07 14:29 
GeneralRe: Dispose Method Pin
N a v a n e e t h31-Jul-07 18:21
N a v a n e e t h31-Jul-07 18:21 
GeneralRe: Dispose Method Pin
Scott Dorman31-Jul-07 19:43
professionalScott Dorman31-Jul-07 19:43 
QuestionConnecting to SQL Server through C#.net Pin
Saba0230-Jul-07 2:32
Saba0230-Jul-07 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.