Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
QuestionUnsafe code compile in clr Pin
Abdul Rahman Hamidy25-Sep-09 6:18
Abdul Rahman Hamidy25-Sep-09 6:18 
AnswerRe: Unsafe code compile in clr Pin
harold aptroot25-Sep-09 6:42
harold aptroot25-Sep-09 6:42 
AnswerRe: Unsafe code compile in clr Pin
PIEBALDconsult25-Sep-09 8:28
mvePIEBALDconsult25-Sep-09 8:28 
GeneralRe: Unsafe code compile in clr Pin
Abdul Rahman Hamidy25-Sep-09 18:06
Abdul Rahman Hamidy25-Sep-09 18:06 
GeneralRe: Unsafe code compile in clr Pin
PIEBALDconsult25-Sep-09 18:27
mvePIEBALDconsult25-Sep-09 18:27 
GeneralRe: Unsafe code compile in clr Pin
Abdul Rahman Hamidy25-Sep-09 18:56
Abdul Rahman Hamidy25-Sep-09 18:56 
GeneralRe: Unsafe code compile in clr Pin
PIEBALDconsult26-Sep-09 4:25
mvePIEBALDconsult26-Sep-09 4:25 
QuestionRelease of resources - System.Collections,Generic.List<t></t> Pin
abosch200025-Sep-09 5:32
abosch200025-Sep-09 5:32 
Hi There,

I have been running around on the net with regards to this question and i cannot seem to find a straight answer. I have created the following class with a list property which is of type System.Collections.Generic.List named "FFamily", one will note that i have also implemented the destructor to release the said list:

public class Person
{
private string FName;
private int FAge;
private List<person> FFamily;

public string Name
{
get { return FName; }
set { FName = value; }
}

public int Age
{
get { return FAge; }
set { FAge = value; }
}

public List<person> Family
{
get { return FFamily; }
}

public Person()
{
FFamily = new List<person>();
}

~Person()
{

FFamily.Clear();
}

//public static Comparison<person> AgeComparison =
// delegate(Person P1, Person P2)
// {
// return P1.Age.CompareTo(P2.Age);
// };

//public static Comparison<person> NameComparison =
// delegate(Person P1, Person P2)
// {
// return P1.Name.CompareTo(P2.Name);
// };
}

I have the following code on the main form to test the functionality:

Person Pers1 = new Person();
Pers1.Age = 24;
Pers1.Name = "Zemus";

Person Pers2 = new Person();
Pers2.Age = 2;
Pers2.Name = "Adrian";

Pers1.Family.Add(Pers2);

List<person> Lst1 = new List<person>();
Lst1.Add(Pers1);

foreach(Person PersTest in Lst1) {
MessageBox.Show(PersTest.Name);

foreach (Person PerTest2 in PersTest.Family)
{
MessageBox.Show(" - "+PerTest2.Name);
}
}

Lst1.Clear();

Now according to various articles on the internet it is not necessary to release any of the above mentioned lists and / or items be managed by the GC. I tried to see for myself whether this happens or not.

First thing i did was run the application and keep pressing the button to execute the code block over and over and watched the task manager and it kept on going up.

The second thing i did was call GC.Collect() and MessageBox.Show(GC.GetTotalMemory(false).ToString()) and i saw that the system would now and again drop this value (or do a collection I assume). Just before the count went down it would fire the destructor for the Person class and clear the Family list.

Now i want to know, considering the main list i am instantiating and considering that I am creating items with nested lists would the GC clean up the main list and all the "Person" objects with their "Family" lists? Do i not need to concern myself with the collection of these items? List does not need to implement "IDisposable" to be managed by the GC?

You see, i have many years of Delphi behind me where the creation and release of memory with respect to object instantiation was all explicit.

Thanks,

Anton
AnswerRe: Release of resources - System.Collections,Generic.List Pin
Not Active25-Sep-09 5:47
mentorNot Active25-Sep-09 5:47 
AnswerRe: Release of resources - System.Collections,Generic.List Pin
Keith Barrow25-Sep-09 6:11
professionalKeith Barrow25-Sep-09 6:11 
QuestionPROJECT WORK [modified] Pin
aravindjayan25-Sep-09 5:21
aravindjayan25-Sep-09 5:21 
AnswerRe: PROJECT WOEK Pin
harold aptroot25-Sep-09 5:26
harold aptroot25-Sep-09 5:26 
GeneralRe: PROJECT WOEK Pin
harold aptroot25-Sep-09 5:51
harold aptroot25-Sep-09 5:51 
GeneralRe: PROJECT WOEK Pin
Kevin Marois25-Sep-09 5:59
professionalKevin Marois25-Sep-09 5:59 
GeneralRe: PROJECT WOEK Pin
harold aptroot25-Sep-09 6:02
harold aptroot25-Sep-09 6:02 
GeneralRe: PROJECT WOEK Pin
Kevin Marois25-Sep-09 6:06
professionalKevin Marois25-Sep-09 6:06 
GeneralRe: PROJECT WOEK Pin
musefan25-Sep-09 6:31
musefan25-Sep-09 6:31 
GeneralRe: PROJECT WOEK Pin
Kevin Marois25-Sep-09 6:51
professionalKevin Marois25-Sep-09 6:51 
GeneralRe: PROJECT WOEK Pin
harold aptroot25-Sep-09 6:33
harold aptroot25-Sep-09 6:33 
GeneralRe: PROJECT WOEK Pin
Kevin Marois25-Sep-09 6:51
professionalKevin Marois25-Sep-09 6:51 
GeneralRe: PROJECT WOEK Pin
OriginalGriff25-Sep-09 8:21
mveOriginalGriff25-Sep-09 8:21 
GeneralRe: PROJECT WOEK Pin
Keith Barrow25-Sep-09 6:55
professionalKeith Barrow25-Sep-09 6:55 
AnswerRe: PROJECT WOEK Pin
Not Active25-Sep-09 5:28
mentorNot Active25-Sep-09 5:28 
GeneralRe: PROJECT WORK Pin
musefan25-Sep-09 6:34
musefan25-Sep-09 6:34 
GeneralRe: PROJECT WORK Pin
aravindjayan25-Sep-09 7:01
aravindjayan25-Sep-09 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.