 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jeremy Guest
|
Posted: Fri Jun 02, 2006 5:15 pm Post subject: Define Strong Pointers, Weak Pointers |
|
|
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
|
Posted: Fri Jun 02, 2006 5:15 pm Post subject: Re: Define Strong Pointers, Weak Pointers |
|
|
"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
|
Posted: Sun Jun 04, 2006 4:06 am Post subject: Re: Define Strong Pointers, Weak Pointers |
|
|
"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 |
|
 |
|
|
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
|
|