Solved

C# Memory usage of classes

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now