Memory management in .Net framework

G

Guest

i'm reading some books on memory mgmt in .Net framework. And here is my
understanding: The memory for each object in .Net comes from managed heap.
The GC is in charge of collecting unused memory and reclaiming memory
automatically.

My questions is for value type variable, is the memory still from managed
heap ?
and what happens if the value type variable is not in use, such as function
exits ?

Your explanation would be appreciated!
 
C

Cor Ligthert

Nicole,

In Net does the value type "variable" not exist.

Although you can say that an object with a value in it is almost a variable.
(Don't try to use it that way we have seen in this newgroup often people
comming from VB6 who tried that, it has no benefits.)

An object is always on the managed heap.

When a value is not in an object it stays in the program stack

The GC is in charge to collect unused objects from the managed heap and
reclaiming memory from that.

When a value is in a method, than it is deleted from the stack as soon as
the method is done.

When the value is created as whatever global (static) value in a class it
stays as long as the class exists.

When a value or an object is in a shared procedure or a module, it lifes as
long as the application runs.

I hope this gives some ideas?

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
In Net does the value type "variable" not exist.

I assume Nicole is referring to variables declared in a type that is a value
type, like 'Dim i As Integer'.
 
C

Cor Ligthert

I assume Nicole is referring to variables declared in a type that is a
value type, like 'Dim i As Integer'.
Not impossible however than there is in my opinion still nothing wrong in my
anser.

Cor
 
C

Cor Ligthert

Nicole,

I mix forever that variable when it is asked with the vb6 variant.

So you can skip the first row of my answer altough when you change in that
variable for variant than it is again right, however not that important.

Cor


(e-mail address removed)...
 
G

Guest

Herfried is right. I mean the value type variable.
But thanks for your threads. I now have a better understanding.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top