?
Solved

C# Memory usage of classes

Posted on 2007-04-03
2
Medium Priority
?
341 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 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