I am new to c# and am trying to dispose of objects taking up large amounts of memory as I've run memory profiling and need to dispose of some resources and call the finalize method for GC. However IDisposable cant implement my class why is this? and how should I implement IDispose to my class?
public class CellItem: IDisposable
{
public int MedicationDispenseId { get; set; }
public Enumerations.Timeslot Timeslot { get; set; }
public DateTime DateAdministered { get; set; }
public void dispose() {
if (this.MedicationDispenseId != null ) {
this.dispose();
}
if (this.Timeslot != null)
{
this.dispose();
}
if (this.DateAdministered != null)
{
this.dispose();
}
}
}
C# is case-sensitive, you want to name your methods starting with capital letter, i.e.
dispose
=> Dispose
Also have a look at Implement IDisposable correctly and yet another good answer from John Skeet.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments