Click here to Skip to main content
15,908,906 members
Home / Discussions / C#
   

C#

 
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 
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 
Firstly,
When posting code use either the <code></code> for inline code, or the <pre></pre> tags for code blocks (like yours).
so


public class Person
{
private List FFamily;

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

public Person()
{
FFamily = new List();
}


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

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



becomes
public class Person
{
private List FFamily;

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

public Person()
{
FFamily = new List();
}


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

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


abosch2000 wrote:
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?


For the most part in .NET, you don't need to implement the destructor or IDisposable, unless there are specific reasons for doing this (e.g. a connection of some sort must be closed, or disposal of child objects needs to take place ion a particular order etc).

You also rarely have to worry about garbage collection. Garbage collection is handled by the .NET framework automatically, any objects that are orphaned are disposed for you periodically. The method the framework uses to determine orphaned objects is quite complicated, but basically it boils down to (as I understand it), if an object is inaccessible from the call stack and is not in an object graph that is accessibile from a call stack, then it is considered orphaned. In the case of list items that have been cleared, the items themselves are orphaned as they no longer appear in the list's tree of objects (presuming there are no other references to the cleared items in other objects). This also happens when a class instance goes out of scope and is not referenced elsewhere.

The disadvantage of the .net framework's implicit collection mechanism is that you don't know exactly when it will happen, just that it happens periodically. In scenerios where memory is a a premium (e.g large numbers of, or very large, objects in the object graph) you might want an explicit Garbage Collection, but more often than not the automatic collection is fine.


Hope this helps.

CCC solved so far: 2 (including a Hard One!)

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 
GeneralRe: PROJECT WORK Pin
harold aptroot25-Sep-09 7:14
harold aptroot25-Sep-09 7:14 
QuestionSQL with C# Pin
sanforjackass25-Sep-09 3:26
sanforjackass25-Sep-09 3:26 

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.