Re: memory leak or not?
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Sat, 4 Nov 2006 13:22:37 +0100
Jon,
Read my whole post,
The first object A from this reply I have showed you is not garbaged as the
MyJonObject is not instanced in this method. The second will, because it
holds outside the method no reference anymore.
object A = MyJonObject;
is different from
string A = MyJonObject.ToString();
And please keep answers by what I wrote; not what you have written that *I*
wrote; if we search on how many times you did that and how many times I
have asked you that when you don't understand my replies to ask specify what
I meant than we get endless messages. Not only by me by the way. I am
writting here mostly in a style expectiong that people are proffesionals not
amateurs in development and only need few words.
Cor
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> schreef in bericht
news:MPG.1fb657bb9eb1833398d5c9@xxxxxxxxxxxxxxxxxxxxxxx
Cor Ligthert [MVP] <notmyfirstname@xxxxxxxxx> wrote:
I did not discuss that and don't have in any way an other opinion. Why
are
you forever proving things that I don't deny.
Well, you said:
<quote>
As it had been a "normal" reference type the object would in my idea
not be garbaged.
</quote>
I've shown that a "normal" reference type *can* be garbage collected.
If that's not what you meant, you should be clearer about what you're
talking about.
I only say that a string is an in the method created object, while non
immutable objects are just references, if they ain't created new.
Where do you get this strange idea that strings behave differently
though? String literals are slightly different, in that they're kept in
a pool somewhere so won't be garbage collected until the application
domain is unloaded, but no-one's mentioned literals in this thread.
I still don't know what you mean by "an in the method created object" -
but strings definitely behave like other objects. If I call:
string x = new string ('y', 10);
that's created a new object which can be garbage collected like any
other. The value of x is just a reference in exactly the same way as it
would be in:
object x = new object();
Perhaps it's best to make this concrete, and go back to my original
example. I'll fill in GrabSomeLongString. How many objects do you
believe are created in the following code:
void Foo()
{
string x = GrabSomeLongString();
Console.WriteLine (x.Length);
// Lots more code here
// Nothing referring to x
// End of method
}
string GrabSomeLongString()
{
return new string ('z', 1000);
}
I believe there's *one* object created, a string, which the variable x
refers to. After Console.WriteLine (x.Length), that string variable is
eligible for garbage collection.
So, how many objects do you think are created, and when do you believe
they're eligible for GC?
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- References:
- Re: memory leak or not?
- From: Marina Levit [MVP]
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- From: Cor Ligthert [MVP]
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- From: Cor Ligthert [MVP]
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- From: Cor Ligthert [MVP]
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- From: Cor Ligthert [MVP]
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- From: Cor Ligthert [MVP]
- Re: memory leak or not?
- From: Jon Skeet [C# MVP]
- Re: memory leak or not?
- Prev by Date: Re: Console application switches for argument values?
- Next by Date: Re: Connection to SQL database on local computer
- Previous by thread: Re: memory leak or not?
- Next by thread: Re: memory leak or not?
- Index(es):
Relevant Pages
|