Title Back Colour Keyoti Title Line Title Curve
Blue Box Top

Disposable Objects and Finalizers - RapidSpell WPF - Forum

Welcome Guest Search | Active Topics | Log In | Register

Options
petegoo
#1 Posted : Friday, September 14, 2012 2:30:47 AM
Rank: Member

Groups: Registered

Joined: 9/14/2012
Posts: 4
It seems that on WpfTextBoxAdapter and possibly other classes a Dispose method has been implemented and also a finalizer. It's a little strange that the classes themselves don't seem to implement IDisposable but apart from that it doesn't seem that the Dispose methods are calling SuppressFinallze. My concern is that this may be resulting in some behaviour we are witnessing where a large tree of objects are spending a long time on the finalizer queue as a result.

Was this intentional?
Jim
#2 Posted : Friday, September 14, 2012 1:56:47 PM
Rank: Advanced Member

Groups: Administrators, Registered

Joined: 8/13/2004
Posts: 2,669
Location: Canada
Hi, I think our use of the name "Dispose" for that method is the confusion. Dispose (not how we've used it, but generally) and IDisposable are for cleaning up unmanaged resources - but we don't actually have any unmanaged resources. When we designed the WPF version of RapidSpell we followed the Win Forms design, and use Dispose to know when to unhook event handlers and unregister from the adorner layer. This is also why we don't call SuppressFinalize, because what we're doing is only performing necessary dereferencing so that the GC can do it's job.

Last week we fixed a bug, where the application doesn't fully close down if the user runs a dialog spell check on a textbox with no errors. I don't know if that could be related to what you're doing, but here it is the soon to be released DLL
https://www.dropbox.com/.../RSWPF-3-NoErrors.zip?m

If I can help further just let me know
Jim


-your feedback is helpful to other users, thank you!

Evaluation Downloads
-your feedback is helpful to other users, thank you!


petegoo
#3 Posted : Friday, September 14, 2012 5:16:16 PM
Rank: Member

Groups: Registered

Joined: 9/14/2012
Posts: 4
Thanks for the updated dll. I'll try that out. Though, if you have no unmanaged resources then there should be no finalizer or you should still call SuppressFinalize on the dispose method. The issue is that the existence of a finalizer will cause the object to survive a GC and get placed on the finalizer queue along with anything it references. This means that potentially large amounts of memory will not get reclaimed until the finalizer thread is run. This can take some time as the process will keep grabbing memory until the GC heuristics decide that finalizers should be run.
Jim
#4 Posted : Saturday, September 15, 2012 1:03:52 AM
Rank: Advanced Member

Groups: Administrators, Registered

Joined: 8/13/2004
Posts: 2,669
Location: Canada
I see what you mean, thanks - please try this build

https://www.dropbox.com/...SWPF-3-Finalizers.zip?m

Jim

-your feedback is helpful to other users, thank you!

Evaluation Downloads
-your feedback is helpful to other users, thank you!


petegoo
#5 Posted : Monday, September 17, 2012 8:46:05 PM
Rank: Member

Groups: Registered

Joined: 9/14/2012
Posts: 4
Thanks, this seems to reduce some of the finalizer work our app is having to do. I would suggest that you keep the finalizer and use SuppressFinalize in the dispose method however as then the finalizer will get ignored if disposed but can be used if someone forgets to dispose.
Jim
#6 Posted : Monday, September 17, 2012 9:02:01 PM
Rank: Advanced Member

Groups: Administrators, Registered

Joined: 8/13/2004
Posts: 2,669
Location: Canada
Thanks, but the reason we didn't go that route with this change was because the dispose/finalizer code was just unhooking handlers and the adorner, and since the finalizer can't run until the handlers are unhooked, it wasn't going to do anything anyway. So there was actually no point in having the finalizer code.

Jim

-your feedback is helpful to other users, thank you!

Evaluation Downloads
-your feedback is helpful to other users, thank you!


petegoo
#7 Posted : Monday, September 17, 2012 9:04:19 PM
Rank: Member

Groups: Registered

Joined: 9/14/2012
Posts: 4
Ok. Cool. Thanks again.
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.




About | Contact | Site Map | Privacy Policy

Copyright © 2002- Keyoti Inc.