Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Observer Pattern: Dangling References
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00354611
Message ID:
00354758
Views:
21
Ken,

If you are going to have an Attach() method, you should have a corollary Detach() method so that an observer can unlink from the item it is observing. You may want to give each of your objects a unique key to make it easier to determine which object is requesting to be detached. When your observer destructs it can request it be Detached, iff the observed item still exists. The observed item should be able to this.aObsevers = .null. if that doesn't seem to be working you might explicitly loop through the array setting each array member to .null.

Are you positive there are no other references that are dangling? Are you using PEMSTATUS() or GETPEM() these are known to under specific conditions cause internal reference count increases that we have absolutely no control over.

You don't have to .null. the oObserver that is marked as lparameter.

>I'm working on an observer pattern utilizing a listbox as the subject, and custom classes (textbox & label) as observers. I'm using the following Attach method in the listbox:
>
lparameter oObserver
>
>if type('This.aObservers(1)') # 'O'
>	x = 1
>else
>	x = alen(this.aObservers) + 1
>endif
>
>dime this.aObservers(x)
>this.aObservers(x) = oObserver
>oObserver = .null.
>
>I can not seem to get rid of these references. When and where should I be clearing them? I've been trying to do it in the destroy event to no avail. I must be missing something...
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform