Should I Use Classes The Ways I Have Been?

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

50 Replies - 11216 Views - Last Post: 22 March 2013 - 12:30 PM Rate Topic: -----

#46 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3568
  • View blog
  • Posts: 11,089
  • Joined: 05-May 12

Re: Should I Use Classes The Ways I Have Been?

Posted 20 March 2013 - 05:05 AM

If you really want to see if things are leaking, use a .NET memory profiler to see. See this SO answer for a list of what is available: http://stackoverflow...d-net-profilers
Was This Post Helpful? 0
  • +
  • -

#47 adn258  Icon User is offline

  • D.I.C Addict

Reputation: 11
  • View blog
  • Posts: 762
  • Joined: 31-August 11

Re: Should I Use Classes The Ways I Have Been?

Posted 21 March 2013 - 02:48 PM

I have done that. I used the clrprofiler. It's a bit confusing for me in learning how to tell if a memory leak has happened by using this. I'm also just curious if there's any way to just add a finalizer to a RTB and the objects I'm creating but there doesn't seem to be. I honestly don't think this is a problem in my case though and perhaps I'm being obsessive.
Was This Post Helpful? 0
  • +
  • -

#48 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: Should I Use Classes The Ways I Have Been?

Posted 21 March 2013 - 03:35 PM

The finalizer idea was meant in part to provide you with a quick and simple check for you to use where applicable as I know you tend to obsess over these things, but it was mainly intended as a learning tool and to offer you a different perspective on what we actually mean when we say an event subscription is causing a so called 'memory leak'. If you are going to be doing any serious memory profiling, you should obviously take the time to learn how to use a good memory profiler.

Anyway, as part of the finalizer check I proposed, there is no reason for you to need to add a finalizer to the RichTextBox class (which you cannot do without sub classing the class). You are supposed to add the finalizer to the event subscriber, not the event publisher, as it is the event subscriber that will be 'leaked' if the publisher outlives it.

This post has been edited by CodingSup3rnatur@l-360: 21 March 2013 - 03:42 PM

Was This Post Helpful? 0
  • +
  • -

#49 adn258  Icon User is offline

  • D.I.C Addict

Reputation: 11
  • View blog
  • Posts: 762
  • Joined: 31-August 11

Re: Should I Use Classes The Ways I Have Been?

Posted 21 March 2013 - 04:40 PM

Sorry coding supernatural I've made this way too confusing and prolonged. There is no secondary event subscriber the event subscriber IS THE MAIN FORM NOW you would have to assume since it's a RTB being added to a tabpage and that tabpage is being added to the tabcontrol on the main form.

This means that there's no way for the RTB i.e. the event publisher to outlive the subscriber correct me if I'm wrong.
Was This Post Helpful? 0
  • +
  • -

#50 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: Should I Use Classes The Ways I Have Been?

Posted 22 March 2013 - 11:18 AM

Yes, I think you've got it. The rich text box is ultimately contained in the form, so it won't outlive the form.
Was This Post Helpful? 1
  • +
  • -

#51 adn258  Icon User is offline

  • D.I.C Addict

Reputation: 11
  • View blog
  • Posts: 762
  • Joined: 31-August 11

Re: Should I Use Classes The Ways I Have Been?

Posted 22 March 2013 - 12:30 PM

Yes and for awhile that was hard for me to understand but I think I got it now. I really appreciate your help again codingsupernatural. I also used CLR profiler and read the instructions about how broken up lines that are separated show memory that should be being freed up and garbage collected but it isn't and I don't appear to have any of that going on so I'm good!!
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4