473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Memory Usage for Objects

When I create an object in VB.NET I define both properties (data) and methods
(code). If I have 1,000 instances of this object stored in a Dictionary as
Dictionary(of int32, object) then I am obviously repeating the data of the
object 1,000 times.

If I understand correctly how objects are constructed, the methods (code) is
only stored once in memory and referenced by each instance of the object.
Thus it does not matter how many methods I have in an object when it comes to
efficiency and memory usage.

When is it a best practice to keep the object "lightweight" (with minimal
code)? Is this the case when we are remoting objects? Are there other reasons
to keep objects that are in collections "lightweight"?

--
Tom Stevens
Jul 21 '07 #1
3 1698
Tom++; wrote:
When I create an object in VB.NET I define both properties (data) and methods
(code).
Properties are not data. The member variables of an object is the data.
Properties are just methods used to access the data.
If I have 1,000 instances of this object stored in a Dictionary as
Dictionary(of int32, object) then I am obviously repeating the data of the
object 1,000 times.

If I understand correctly how objects are constructed, the methods (code) is
only stored once in memory and referenced by each instance of the object.
Thus it does not matter how many methods I have in an object when it comes to
efficiency and memory usage.
Correct.
When is it a best practice to keep the object "lightweight" (with minimal
code)? Is this the case when we are remoting objects? Are there other reasons
to keep objects that are in collections "lightweight"?
Light weight refers to the data members of an object, not the methods.
As the number of methods doesn't impact the size of the object
instances, it's very rarely a concern at all. I don't know of any
sitation at all where it would matter.

--
Göran Andersson
_____
http://www.guffa.com
Jul 22 '07 #2
Hi Tom,

I agree with Anderson that the properties in a class are methods, not data.

What you described about how objects are constructed is correct.

In my opinion, even if each object has a lot of member variables, it
wouldn't cause the program to perform worse, because it won't add too much
of the object size.

If you have any concern, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 23 '07 #3
Thank you for your fast response.

Yes, I did mean member variables and not properties.
"Göran Andersson" wrote:
Tom++; wrote:
When I create an object in VB.NET I define both properties (data) and methods
(code).

Properties are not data. The member variables of an object is the data.
Properties are just methods used to access the data.
If I have 1,000 instances of this object stored in a Dictionary as
Dictionary(of int32, object) then I am obviously repeating the data of the
object 1,000 times.

If I understand correctly how objects are constructed, the methods (code) is
only stored once in memory and referenced by each instance of the object.
Thus it does not matter how many methods I have in an object when it comes to
efficiency and memory usage.

Correct.
When is it a best practice to keep the object "lightweight" (with minimal
code)? Is this the case when we are remoting objects? Are there other reasons
to keep objects that are in collections "lightweight"?

Light weight refers to the data members of an object, not the methods.
As the number of methods doesn't impact the size of the object
instances, it's very rarely a concern at all. I don't know of any
sitation at all where it would matter.

--
Göran Andersson
_____
http://www.guffa.com
Jul 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vincent | last post by:
Hi I have a problem with pear DB my code : for ($i=0;$i<100000;$i) { $sql = "select id from table where id=x";
3
by: Ian | last post by:
Hi all, I have a problem. I have an application which needs to work with a lot of data, but not all at the same time. It is arranged as a set of objects, each with lots of data that is created...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
7
by: George Gre | last post by:
Hi, I wrote a c# programme that listens to incoming TCP requests and services them. This programme is meant to be running as long as the server its installed on is running. So we assume for...
20
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
5
by: SDS | last post by:
I am writing an ASP.NET application (in C#) that, as part of a particular response, populates a MemoryStream object with binary data that is being collected from a Process object's StandardOutput. ...
16
by: JCauble | last post by:
We have a large Asp.net application that is currently crashing our production servers. What we are seeing is the aspnet_wp eat up a bunch of memory and then stop unexpectedly. Does not recycle. ...
4
by: Hermann Maier | last post by:
hi, i need to find out the memory usage of a specific function that i use in my program. this function does some recursive calculations and i want my program to display the amount of memory the...
17
by: Frank Rizzo | last post by:
Hello, I've compiled my app for AnyCPU setting in vs2005. Then I tried the app on both 32-bit Windows 2003 R2 and 64-bit Windows 2003 R2. The memory usage of the application when working on...
3
by: crazy420fingers | last post by:
I'm running a python program that simulates a wireless network protocol for a certain number of "frames" (measure of time). I've observed the following: 1. The memory consumption of the program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.