Solved

C# Memory usage of classes

Posted on 2007-04-03
2
330 Views
Last Modified: 2013-11-07
Given is a class with several static and several internal methods.

As far as i know, the static ones are only created once, no matter how many instances of the class i have, right?
Consequently the internal methods should be created every time one creates an instance of this class, right?
Would it then not be better to declare all methods of a class as static and hand them over the instance of the class every time we call them?
0
Comment
Question by:makronium
2 Comments
 
LVL 3

Expert Comment

by:Nico
ID: 18842998
Well, yes and no. It'd be procedural programming then. You get that when you use C and have only a bunch of methods and pass structures around :)

I doubt that when you instantiate a class that all the methods are copied in memory, too. Why are you worrying about this?
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 18843149
Making methods static has no effect on memory.  The code for a class only exists once, whether static or not.  The _fields_ of a class, however, will only exist once if they are static.  

The only reason to make a _Method_ static is if does not use any instance data.  
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question