Simple problem: Why does this cause a massive memory leak?

  • Thread starter Thread starter Simon
  • Start date Start date
Miha said:
Cor,

There are two issues with your solution:
1. It won't compile as you are accessing a variable before its declaration
2. It doesn't matter whether you invoke Clear or not as reference goes
out of the scope anyway.


Yeah - I've got to agree with that assesment I'm afraid. Unless I'm
being particularly thick, the code as suggested wouldnt even compile -

// Won't compile
tblGSPositions.Clear();
GPSPositionTable tblGPSPositions = new GPSPositionTable();

Thanks

Simon
 
Miha,

I agree with you that I missed the declaration part and this one won't go,
however the idea was that often the problem is that the old object stays,
because although it goes out of scope, holds or has references to it.

Maybe will this go with the declaration global. I trying this with the
shortes code I can think about.

cor
Cor,

There are two issues with your solution:
1. It won't compile as you are accessing a variable before its declaration
2. It doesn't matter whether you invoke Clear or not as reference goes out
of the scope anyway.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Cor Ligthert said:
Simon,

I mean before it is created.

GPSPositionTableAdapter da = new GPSPositionTableAdapter();
tblGSPositions.Clear();
'At least the table which will be replaces loses now his rows, and I hope
its references.
'Be aware that not the same table is used again, only the references is
replaced by another one with
'your sentence bellow. If there are references to the existing those will
stay as long as the program lives.
GPSPositionTable tblGPSPositions = new GPSPositionTable();

Cor
 
Cor Ligthert said:
Miha,

I agree with you that I missed the declaration part and this one won't go,
however the idea was that often the problem is that the old object stays,
because although it goes out of scope, holds or has references to it.

If something is holding the reference (lets say parent) to instance you want
get rid of then you have to make sure to either
a) drop that reference
b) make sure every reference to parent is dropped
so the graph isn't referenced from outside.
Either way Clear would not help.
 
Back
Top