Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,084 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,550 people online right now. Registration is fast and FREE... Join Now!




Clear() for an object

 
Reply to this topicStart new topic

Clear() for an object

killnine
8 Apr, 2008 - 06:38 AM
Post #1

D.I.C Head
**

Joined: 12 Feb, 2007
Posts: 107



Thanked: 3 times
My Contributions
So lets say I have an object called "SignalList", which is a class that performs a bunch of useful actions on a List<T> of custom Signal objects (each signal is added via .Add(Signal someNewSignal)).

If I made a clear() method, that removed all the Signal objects from the list, the Signal's would still be in memory, right?

Is this a waste? Should I let the GC take care of the signals after a clear() call? Should I manually erase them all? If so, how?


User is offlineProfile CardPM
+Quote Post

baavgai
RE: Clear() For An Object
8 Apr, 2008 - 07:34 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
The google term you're looking for is Garbage Collection.

The short version. Once an object has no reference to it, it's memory will be released. However, the system decides when, not the programmer. There are ways to beg, but they'll only get you so far. Stop complaining, it's managaged code and we're managing it, and you aren't. tongue.gif

Java has the identical issue, if it makes you feel any better.

User is offlineProfile CardPM
+Quote Post

killnine
RE: Clear() For An Object
8 Apr, 2008 - 08:19 AM
Post #3

D.I.C Head
**

Joined: 12 Feb, 2007
Posts: 107



Thanked: 3 times
My Contributions
QUOTE(baavgai @ 8 Apr, 2008 - 08:34 AM) *

The google term you're looking for is Garbage Collection.

The short version. Once an object has no reference to it, it's memory will be released. However, the system decides when, not the programmer. There are ways to beg, but they'll only get you so far. Stop complaining, it's managaged code and we're managing it, and you aren't. tongue.gif

Java has the identical issue, if it makes you feel any better.



Hey, I am all for the garbage collector. A month or so ago I was reading up on XNA, which is C#-based, and it discussed how the garbage collector worked, and the various states an object can be in before its removed from memory. Pretty interesting.

I just wanted to make sure I wasn't putting myself into a position where my application was going to blow up in size indefinitely after clearing the SignalList object.

Neato!


Thanks Baavgai, I try to look up questions before I ask, but I often miss things or dont understand how they are described in other locations. Hopefully my questions will benefit others, though.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:59PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month