Memory USage

  • Thread starter Thread starter CJ Taylor
  • Start date Start date
C

CJ Taylor

If I wanted to find out exactly how much memory a particular variable was
using, how would I go about that. Or where to look for information would be
appreciated. Just need a class/namespace

Thanks,
CJ
 
CJ Taylor said:
If I wanted to find out exactly how much memory a particular variable
was using, how would I go about that. Or where to look for
information would be appreciated. Just need a class/namespace

Marshal.Sizeof returns the size when marshalled to unmanaged code. Don't
know how to get the managed size. I think we are not allowed to know this
because automatic memory management is done. ;-)


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Armin Zingler said:
Marshal.Sizeof returns the size when marshalled to unmanaged code. Don't
know how to get the managed size. I think we are not allowed to know this
because automatic memory management is done. ;-)

Yeah found the sizeOf for the unmanaged types. Useless considering I want
to know what is spiking my managed types. Damnit.

=)

Well, sometimes Automatic Memory Managment sucks.
=)
 
CJ Taylor said:
Yeah found the sizeOf for the unmanaged types. Useless considering I
want to know what is spiking my managed types. Damnit.

=)

Well, sometimes Automatic Memory Managment sucks.
=)

Yes, VB programmers always wanted more influence - but they got less. ;-)
 
* "Armin Zingler said:
Marshal.Sizeof returns the size when marshalled to unmanaged code. Don't
know how to get the managed size. I think we are not allowed to know this
because automatic memory management is done. ;-)

Or (in some cases): 'Len':

<msdn>
Returns an integer containing either the number of characters in a
string or the number of bytes required to store a variable.
</msdn>
 
Hmm, doesn't appear to work with classes. At least those that inhert from
System.ComponentModelComponent.

keep getting a runtime error saying invalid cast exception
 
* "Armin Zingler said:
Yes, VB programmers always wanted more influence - but they got less. ;-)

Even C# programmers got less influence than in C++.
 
Even C# programmers got less influence than in C++.

Even C++ programmers got less infuence than in assambler

Even Assembler programmers got less influence than hard "op" code
programmers

:-)

Cor
 
Hi CJ,

Finding the lenght of a variable is intresting but gives no information at
all.

Mostly uses one (processor) operation needed to process that value much more
memory than the value it self.

(I did never look to the machine code from a program anymore for a very long
time, however I assume, that it will be normal that processing a 16 bit
value will take much more memory in a 32bit processor system than a 32bit
value)

Just my thought

Cor
 
* "Cor Ligthert said:
Even C++ programmers got less infuence than in assambler

Even Assembler programmers got less influence than hard "op" code
programmers

:-)

ACK. In a high-level language we should not have to care about
limitation of memory at all ;-).
 
Cor,

I was watching for changes in memory by stepping through code and using the
Gc.GetTotalMemory() method. How accurate it is, I dunno. I was just
stepping through each variable and recording the delta. that gave me my
estimated variable size.

I recorded it into an excel spreadsheet and watched as I created my loop. I
don't know how often the gc is called in debug, but I'm assuming not very
often (because memory did keep growing.)

Now I know according to a couple articles I read yesterday that the GC is
only called when required, i.e. when memory is low or another .net app
starts requesting resources.

So as I record my findings, I start to have some really basic questions
about what I'm doing.

First, TypeSafe Event Handlers using delegates...

I call

AddHandler myClassName.MyEvent, New MyEventHandler(AddressOf
onMyEventHandlerMethod)

afterwards I remove it with

RemoveHandler myClassName.MyEvent, New MyEventHandler(AddressOf
onMyEventHandlerMethod

Is this wrong? should I not be calling a function pointer on the remove,
should I just use the AddressOf Operator?

2nd.. Declaring eventArgs. Should I?

a) Declare a local variable and then raise, or
b) create the variable within the event raise..

i.e.

a)

Dim e as MyEventArgs

e = new MyEventArgs(myArg1,myArg2)

RaiseEvent myEvent(me,e)

e = nothing

or

b)

RaiseEvent myEvent(me, new MyEventArgs(myArg1,myArg2))


Also, I noticed that calling a Try actually takes up 8k of memory, is this
because it uses the API Function GetLastWindowsError? Should I reduce the
amount of Try/Catch's I use? I remember reading something by Gunnerson I
believe regarding this type of error checking having large overhead.

I do have a nearly 50 meg dataset (required, would be alot bigger if not
filtered) and I did call GC.Collect once, which reduced it down some, but I
do'nt know if anything was promoted to Gen1 or Gen2 in the mean time.
Didn't check that.

Weird thing, I saw application.DoEvents calls take up 8k of memory, figured
that was because of a thread swap or something.

So, here is my question. Now as this thing goes on, memory just keeps
getting consumed, up to about a gig (well higher, my commit charge rises to
2.5 gig overall) and I'm destorying variables, disposing classes and
clearing datasets, yet memroy never seems to be reclaimed. I tried calling
the GC often and was monitoring that with a memory profiler by SciTech.
That is firing just fine. And it reclaims a "little" memory, but maybe only
a meg at best. So this thing keeps going to a gig.

So my last option as I see it is to set my MaxProcessSize (I think thats
what the method is) to like 200 meg, but I'm worried about this affecting
performance. I jsut know the machiens this will run on don't have the
horsepower mine does, and certainly can't pop up a gig. I'm continuing to
try to streamline it more, but don't know what else I can do...

Advice would be appreciated.

-CJ
 
Hi CJ,

Do not overestimate my knowledge.

All I know is from long experience in a wide area of computing not only
programming

One of the things they have said from NT, is that it is build on the
architecture of the IBM 360 system, the thing I did not like from that
system was that as far as I know did every time allocate huge amount of
memory partitions. However I never saw more information about that in
relation to NT (however you will see that an ME computer uses overall less
memory than a NT so I think it is doing it in a kind of same way as I
thought with the 360).

The sense of my previous message was, when you are searching for memory
problems do not search for values, search for the processes with that.

One of the most terrible in that (and easy to find) is a recursive loop
where in is memory allocated and not made free again.

I think also however never tested it that there can be problems with let say
hidden references, which stay. I did understand from Jay B. that an object
would only be released when there is not one reference anymore to it in the
managed environment.

What I would do first in your situation was to see if I have recursive
processes, which create values, or unmanaged resources.

The values themselves are not important anymore in modern computing in my
opinion when is not in a repetitive situation.

Cor
 
Cor,

Thanks for the response.

I'm not going for values, but just total memory thats being consumed. I was
just looking at different things that multipled 1 million times could add
up. I've checked for recursive calls and such (recursion is kinda my thing
=)) and I'm not doing anything like that.

One thing that has made this diffucult is that one of the components I use
heavily was Obfusicated and I kinda wonder about the quality of their
programming (ComponentOne) so its hard to debug if thats a problem.

I'm clearing datasets, removing all references (using x = nothing) or
calling dispose when needed. I know with dispose if I don't kill my
reference GC will ignore it (especially if it's in a higher gen because they
get called a lot less). So now Im just looking for anything to fix this.
 
Hi CJ,

Are you not able to copy your project, delete that Component One, replace it
with a simpler control just to test, and than check what it does.

Just an idea?

Cor
 
Hi CJ,

I did not mean for ever, just in a test copy, when it is there it saves you
looking furter and when it is not there you are not all the time in doubt
that it is maybe there.
 
Back
Top