473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Memory USage

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
Nov 20 '05 #1
18 1326
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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

Nov 20 '05 #2

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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. ;-)


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.
=)

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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

Nov 20 '05 #4
* "Armin Zingler" <az*******@freenet.de> scripsit:
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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. ;-)


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>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Heh...

Thats interesting...

well lets see what she does!
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "Armin Zingler" <az*******@freenet.de> scripsit:
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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. ;-)


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>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #6
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "Armin Zingler" <az*******@freenet.de> scripsit:
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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. ;-)


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>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7
* "Armin Zingler" <az*******@freenet.de> scripsit:
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. ;-)


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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
"CJ Taylor" <[cege] at [tavayn] dit commmmm> schrieb
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


I knew, that's why I didn't mention it - in opposite to Herfried. ;-)))
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
* "Armin Zingler" <az*******@freenet.de> scripsit:
keep getting a runtime error saying invalid cast exception


I knew, that's why I didn't mention it - in opposite to Herfried. ;-)))


That's why I said "in some cases"...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10
> 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
Nov 20 '05 #11
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
Nov 20 '05 #12
* "Cor Ligthert" <no**********@planet.nl> scripsit:
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

:-)


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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #13
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



"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ui*************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #14
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

Nov 20 '05 #15
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.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #16
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
Nov 20 '05 #17
We're a little too far to remove crucial data access components. =-)
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #18
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.
with a simpler control just to test, and than check what it does.

Nov 20 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: rbt | last post by:
Would a Python process consume more memory on a PC with lots of memory? For example, say I have the same Python script running on two WinXP computers that both have Python 2.4.0. One computer has...
5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
2
by: Jarvis | last post by:
I've made a testing program to test the memory usage of some Data Forms. I create a MDI parent form with one single MDI child form, which is a Data Form generated by .NET Data Form Wizard. To...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
20
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
13
by: Ilias Lazaridis | last post by:
How to detect memory leaks of python programms, which run in an environment like this: * Suse Linux 9.3 * Apache * mod_python The problem occoured after some updates on the infrastructure....
1
by: yzghan | last post by:
Hi all, I feel that my python script is leaking memory. And this is a test I have: log.write(" " + "test() ... memory usage: " + " ".join(repr(i/(1024*1024)) for i in getMemInfo()) + "\n") m...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.