473,394 Members | 1,734 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,394 software developers and data experts.

Q: Release a class from memory (NewBee quiz)

Hi!

I have a class like this

Class MyClass
{
Public MyClass()
{
// Doing stuff
}

private string myVar;

and a lot of more code.

}

Now in my Main program i declare this line

private MyClass myClass;

and in a procedure i do the folowing

private void dotest()
{
myClass = new MyClass();
}

Now the myClass is in memory att all time.

When i am thru with the myClass how do "disintegrate" the class, that is
remove it from memory,
releasign resourses?

Regards
Martin

Oct 23 '07 #1
1 1199
Martin wrote:
[...]
When i am thru with the myClass how do "disintegrate" the class, that is
remove it from memory, releasign resourses?
It's unusual, but not unheard of, to have a class allocated and stored
in some static field when it's only going to be needed some of the time
and not others. In those situations, you can simply set the variable
storing the reference to null when you no longer need the class. As
soon as you do that, the instance becomes eligible for garbage
collection, and the memory will be reclaimed when it's needed, if not
sooner.

Keeping in mind to follow the conventions for calling
IDisposable.Dispose() when necessary before setting the variable to
null, of course. This may or may not apply, depending on whether
MyClass implements IDisposable.

Pete
Oct 23 '07 #2

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

Similar topics

5
by: Rodrigue | last post by:
I have code where I populate a data table using visual basic.net code. I call the clear method on the table but it does not seem to release the memory. When I populate the table again, the memory...
2
by: tvn007 | last post by:
Could someone please help me or point/explain to me why the error in line 46 ? ////////////////////////Error message://////////////////////////////// bash-2.05b$ g++ test3.cpp test3.cpp: In...
4
by: DAL | last post by:
I want to build my kid a program that cycles through questions (using a label for the question), and lets him choose one of two radio buttons for the right answer. How do I get every set of...
6
by: laikon | last post by:
Hi, everyone, below is my program to test static pointer data member; class A { private: static A* p; protected: A() {} public: static A* init()
2
by: Epetruk | last post by:
Hello, I have a problem where an application I am working on throws an OutOfMemoryException when I run it in Release mode, whereas it doesn't do this when I am running in Debug. The...
5
by: consternation | last post by:
I can't find neither in tutorial nor with google It's all about isinstance, or __class__. How to test that an object is an instance of my X class?? Do I have this problems because I stre my...
2
by: 2b|!2b==? | last post by:
I am having linkage errors in my release build as ff: ------ Build started: Project: myModule, Configuration: Release Win32 ------ Linking... Creating library c:\mypath\myModule.lib and object...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
3
by: empiresolutions | last post by:
I am building a app that creates quizzes. This is how it goes - - Create Quiz - Provide up to 10 different types of Quiz Results - Give up to 50 Questions - Each Question has up to 10 possible...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.