3

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();

                }
            }

        }
user2708073
  • 169
  • 4
  • 15
  • Even if you correct the casing, calling `this.Dispose` inside `Dispose` is a bad idea. `int` and `DateTime` don't implement `IDisposable`, so you probably shouldn't implement `IDisposable` on `CellItem` at all. – Henrik Aug 23 '13 at 10:44
  • True. Thanks After some reading I've come to the same conclusion. – user2708073 Aug 23 '13 at 12:46

1 Answers1

3

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.

Community
  • 1
  • 1
oleksii
  • 35,458
  • 16
  • 93
  • 163