?
Solved

C# Memory usage of classes

Posted on 2007-04-03
2
Medium Priority
?
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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