Click here to Skip to main content
15,892,059 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Use LinQ in silverlight Pin
Mycroft Holmes15-Mar-11 0:42
professionalMycroft Holmes15-Mar-11 0:42 
GeneralRe: Use LinQ in silverlight Pin
Pete O'Hanlon15-Mar-11 1:42
mvePete O'Hanlon15-Mar-11 1:42 
GeneralRe: Use LinQ in silverlight Pin
Jammer15-Mar-11 3:33
Jammer15-Mar-11 3:33 
GeneralRe: Use LinQ in silverlight Pin
Mycroft Holmes15-Mar-11 12:26
professionalMycroft Holmes15-Mar-11 12:26 
QuestionProblem with executing LINQuery from xmal page Pin
yrishi13-Mar-11 20:19
yrishi13-Mar-11 20:19 
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 
Eek.

I'm using the Mediator pattern (a variation of the one from MVVM Foundation) using weak references to allow Messages to be sent to View Models while not keeping a reference to that view model.

I had a load of VMs created, each registered for messages. When a View is 'closed' all references to the VM are removed (including the DataContext of the view)

So with no references it should be garbage collected, right?

Well if I use a profiler, it does seem to disappear from the map. All good.

So another part of the program sends a message to which my hopefully-garbage collected VM was responding.

Do you think the VM with no references responds to the message? The VM with no references? Yes - it Does! Even though I'm only accessing it via Weak references, and there are no real references to it, it has not been garbage collected .

So a VM which should have been disposed of, handles a message!!!!!!

Help!

I've a work-around - I force Garbage Collection after removing the reference to the VM from the View - but that feels ugly to me.

So the real solution would seem, to me, to remove all messages for a VM when the final reference to the VM is removed.
But that's a little pro-active (i.e. I am relying on the programmer writing code to remember to remove messages which is just about as likely to happen as the programmer removing all event handlers across objects!)

so now I am wondering is it possible, using a weak reference, to check if an object has any strong references? If I can do so, then I can automatically ignore sending messages to un-GarbageCollected objects that have no references (and remove those messages from my Mediator collection.

(I emboldened the actual question as I do tend to waffle a lot and I know you guys are busy chaps)
___________________________________________
.\\axxx
(That's an 'M')

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 
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 

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.