Click here to Skip to main content
15,909,953 members
Home / Discussions / WPF
   

WPF

 
QuestionMicrosoft Ribbon Icons Pin
boggs12-Mar-11 9:16
boggs12-Mar-11 9:16 
AnswerRe: Microsoft Ribbon Icons Pin
Abhinav S13-Mar-11 19:10
Abhinav S13-Mar-11 19:10 
QuestionWeak reference keeping objects alive with Mediator Pin
_Maxxx_11-Mar-11 1:41
professional_Maxxx_11-Mar-11 1:41 
AnswerRe: Weak reference keeping objects alive with Mediator Pin
Pete O'Hanlon11-Mar-11 2:48
mvePete O'Hanlon11-Mar-11 2:48 
GeneralRe: Weak reference keeping objects alive with Mediator Pin
_Maxxx_11-Mar-11 18:06
professional_Maxxx_11-Mar-11 18:06 
AnswerRe: Weak reference keeping objects alive with Mediator Pin
SledgeHammer0111-Mar-11 8:37
SledgeHammer0111-Mar-11 8:37 
GeneralRe: Weak reference keeping objects alive with Mediator Pin
_Maxxx_11-Mar-11 18:11
professional_Maxxx_11-Mar-11 18:11 
GeneralRe: Weak reference keeping objects alive with Mediator Pin
SledgeHammer0111-Mar-11 20:43
SledgeHammer0111-Mar-11 20:43 
The IsAlive property gives you some safe guards, but there is still kind of a race condition. WeakReferences are only there so you don't lock an object from getting GC'ed (duh), but as Pete explained, its easy for an object to go back and forth between weak only and weak & strong. Also, in the example I gave you, its entirely too easy to completely defeat the purpose of weak references because if your object is init'ed inline like that, it'll get GC'ed right away and you'll be debugging code for hours. In that case, you'd need to keep a strong reference to it anyway.

I remember working on a piece of code, I forget what it was right now, but it was something related to commanding & event handlers in some part of .NET (buttons I think). Anyways, I subbed to an event and couldn't for the life of me figure out why the event handler was only getting called once.

Turns out Microsoft had decided to use a weak reference for that particular thing and:

blah.whatever += new EventHandler(...);

was getting GC'ed right away (the event handler I mean was getting GC'ed).

I had to save a strong reference to the event handler in my class. I thought that was really ugly.

Best to avoid weak references IMO. They are often tricky to debug when you forget they are there and just kind of serve as a band aid for sloppy programming.

If a view doesn't unsub from something and causes a leak, why not fix the view rather then hide the problem?
GeneralRe: Weak reference keeping objects alive with Mediator Pin
_Maxxx_13-Mar-11 1:39
professional_Maxxx_13-Mar-11 1:39 
GeneralRe: Weak reference keeping objects alive with Mediator Pin
_Maxxx_13-Mar-11 15:10
professional_Maxxx_13-Mar-11 15:10 
QuestionA basic KIOSK application using WPF/ Silverlight Pin
Member 365700710-Mar-11 20:50
Member 365700710-Mar-11 20:50 
AnswerRe: A basic KIOSK application using WPF/ Silverlight Pin
Abhinav S10-Mar-11 21:24
Abhinav S10-Mar-11 21:24 
AnswerRe: A basic KIOSK application using WPF/ Silverlight Pin
Richard MacCutchan10-Mar-11 22:31
mveRichard MacCutchan10-Mar-11 22:31 
GeneralRe: A basic KIOSK application using WPF/ Silverlight Pin
Member 365700710-Mar-11 23:02
Member 365700710-Mar-11 23:02 
GeneralRe: A basic KIOSK application using WPF/ Silverlight Pin
Richard MacCutchan10-Mar-11 23:48
mveRichard MacCutchan10-Mar-11 23:48 
QuestionMVVM Messenger / Mediator question Pin
_Maxxx_9-Mar-11 15:29
professional_Maxxx_9-Mar-11 15:29 
AnswerRe: MVVM Messenger / Mediator question Pin
SledgeHammer019-Mar-11 17:21
SledgeHammer019-Mar-11 17:21 
AnswerRe: MVVM Messenger / Mediator question Pin
Pete O'Hanlon9-Mar-11 20:06
mvePete O'Hanlon9-Mar-11 20:06 
GeneralRe: MVVM Messenger / Mediator question Pin
_Maxxx_9-Mar-11 21:25
professional_Maxxx_9-Mar-11 21:25 
GeneralRe: MVVM Messenger / Mediator question Pin
Pete O'Hanlon9-Mar-11 21:33
mvePete O'Hanlon9-Mar-11 21:33 
GeneralRe: MVVM Messenger / Mediator question Pin
_Maxxx_9-Mar-11 22:57
professional_Maxxx_9-Mar-11 22:57 
GeneralRe: MVVM Messenger / Mediator question Pin
Pete O'Hanlon9-Mar-11 23:12
mvePete O'Hanlon9-Mar-11 23:12 
GeneralRe: MVVM Messenger / Mediator question Pin
_Maxxx_9-Mar-11 23:45
professional_Maxxx_9-Mar-11 23:45 
GeneralRe: MVVM Messenger / Mediator question Pin
Pete O'Hanlon10-Mar-11 0:14
mvePete O'Hanlon10-Mar-11 0:14 
GeneralRe: MVVM Messenger / Mediator question Pin
_Maxxx_10-Mar-11 1:00
professional_Maxxx_10-Mar-11 1:00 

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.