BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Define Strong Pointers, Weak Pointers

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Jeremy
Guest





PostPosted: Fri Jun 02, 2006 5:15 pm    Post subject: Define Strong Pointers, Weak Pointers Reply with quote



In a thread on the iobserver pattern last month there was reference to
strong and weak pointers or references. A quick search doesn't reveal a
definition. Can someone enlighten me on what these are?

Jeremy
Back to top
Bob Dawson
Guest





PostPosted: Fri Jun 02, 2006 5:15 pm    Post subject: Re: Define Strong Pointers, Weak Pointers Reply with quote



"Jeremy" <jeremy> wrote
Quote:
strong and weak pointers or references.

if the discussion was in the context of .NET, then this
http://msdn2.microsoft.com/en-us/library/system.weakreference.aspx

A weak reference allows what might be called 'opportunistic
referencing'--you keep a reference on an object, but one that doesn't
prevent it from being collected if nothing else is using it.

bobD
Back to top
Joanna Carter [TeamB]
Guest





PostPosted: Sun Jun 04, 2006 4:06 am    Post subject: Re: Define Strong Pointers, Weak Pointers Reply with quote



"Jeremy" <jeremy> a écrit dans le message de news:
448066f2 (AT) newsgroups (DOT) borland.com...

| In a thread on the iobserver pattern last month there was reference to
| strong and weak pointers or references. A quick search doesn't reveal a
| definition. Can someone enlighten me on what these are?

In the context of interfaces Delphi for Win32 :

If you have mutual interface references between to objects, then neither of
the objects will be released due to bothe "normal" references being strong -

IOne = interface
end;

ITwo = interface
end;

TOne = class(...IOne)
private
fTwo: ITwo;
public
property Two: ITwo
read fTwo;
end;

TTwo = class(...ITwo)
private
fOne: IOne;
public
property One: IOne
read fOne;
end;

....but if you want to avoid this kind of memory leak, then you replace one
of these references with a Pointer

TTwo = class(...ITwo)
private
fOne: Pointer;
function GetOne: IOne;
public
property One: IOne
read GetOne;
end;

function TTwo.GetOne: IOne;
begin
result := IOne(fOne);
end;

Using the pointer does not increase the reference count on the IOne ref,
therefore breaking the deadlock.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.