Solved

C# Memory usage of classes

Posted on 2007-04-03
2
329 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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