No subject


Mon Aug 10 18:29:21 EDT 2009


fact that these classes have build a cycle of
relationships is an indication that they

                 "know to much"

about the others, and that you are in the
borderline situation of breaking their
encapsulation.


In general, if Class A knows about class B,
then Class B shouldn't need to know about
Class A.

You may want to reconsider the design,
before you go for adopting the WeakPointer.



    Regards,


          Luis


------------------------

Here is the Valgrind output for both cases:


valgrind --leak-check=3Dfull     ./SmartPointer1
=3D=3D8256=3D=3D Memcheck, a memory error detector.
=3D=3D8256=3D=3D Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward e=
t al.
=3D=3D8256=3D=3D Using LibVEX rev 1884, a library for dynamic binary transl=
ation.
=3D=3D8256=3D=3D Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
=3D=3D8256=3D=3D Using valgrind-3.4.1-Debian, a dynamic binary instrumentat=
ion
framework.
=3D=3D8256=3D=3D Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward e=
t al.
=3D=3D8256=3D=3D For more details, rerun with: -v
=3D=3D8256=3D=3D
A Constructor
B Constructor
C Constructor
=3D=3D8256=3D=3D
=3D=3D8256=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 fr=
om 1)
=3D=3D8256=3D=3D malloc/free: in use at exit: 160 bytes in 3 blocks.
=3D=3D8256=3D=3D malloc/free: 4 allocs, 1 frees, 168 bytes allocated.
=3D=3D8256=3D=3D For counts of detected errors, rerun with: -v
=3D=3D8256=3D=3D searching for pointers to 3 not-freed blocks.
=3D=3D8256=3D=3D checked 113,372 bytes.
=3D=3D8256=3D=3D
=3D=3D8256=3D=3D 160 (56 direct, 104 indirect) bytes in 1 blocks are
definitely lost in loss record 3 of 3
=3D=3D8256=3D=3D    at 0x40269EE: operator new(unsigned int) (vg_replace_ma=
lloc.c:224)
=3D=3D8256=3D=3D    by 0x805DD8E: itk::B::New() (SmartPointer1.cxx:66)
=3D=3D8256=3D=3D    by 0x805D00A: main (SmartPointer1.cxx:92)
=3D=3D8256=3D=3D
=3D=3D8256=3D=3D LEAK SUMMARY:
=3D=3D8256=3D=3D    definitely lost: 56 bytes in 1 blocks.
=3D=3D8256=3D=3D    indirectly lost: 104 bytes in 2 blocks.
=3D=3D8256=3D=3D      possibly lost: 0 bytes in 0 blocks.
=3D=3D8256=3D=3D    still reachable: 0 bytes in 0 blocks.
=3D=3D8256=3D=3D         suppressed: 0 bytes in 0 blocks.



valgrind --leak-check=3Dfull    ./SmartPointer2
 =3D=3D8259=3D=3D Memcheck, a memory error detector.
=3D=3D8259=3D=3D Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward e=
t al.
=3D=3D8259=3D=3D Using LibVEX rev 1884, a library for dynamic binary transl=
ation.
=3D=3D8259=3D=3D Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
=3D=3D8259=3D=3D Using valgrind-3.4.1-Debian, a dynamic binary instrumentat=
ion
framework.
=3D=3D8259=3D=3D Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward e=
t al.
=3D=3D8259=3D=3D For more details, rerun with: -v
=3D=3D8259=3D=3D
A Constructor
B Constructor
C Constructor
C Destructor
B Destructor
A Destructor
=3D=3D8259=3D=3D
=3D=3D8259=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 fr=
om 1)
=3D=3D8259=3D=3D malloc/free: in use at exit: 0 bytes in 0 blocks.
=3D=3D8259=3D=3D malloc/free: 4 allocs, 4 frees, 168 bytes allocated.
=3D=3D8259=3D=3D For counts of detected errors, rerun with: -v
=3D=3D8259=3D=3D All heap blocks were freed -- no leaks are possible.

--00151758f83e2a300b047543d5e5
Content-Type: text/plain; charset=US-ASCII; name="CMakeLists.txt"
Content-Disposition: attachment; filename="CMakeLists.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_g0gnrzq42

Q01BS0VfTUlOSU1VTV9SRVFVSVJFRChWRVJTSU9OIDIuNCkKSUYoQ09NTUFORCBDTUFLRV9QT0xJ
Q1kpCiAgQ01BS0VfUE9MSUNZKFNFVCBDTVAwMDAzIE5FVykKRU5ESUYoQ09NTUFORCBDTUFLRV9Q
T0xJQ1kpCgoKUFJPSkVDVChTbWFydFBvaW50ZXIpCgpGSU5EX1BBQ0tBR0UoSVRLIFJFUVVJUkVE
KQpJTkNMVURFKCR7SVRLX1VTRV9GSUxFfSkKCkFERF9FWEVDVVRBQkxFKFNtYXJ0UG9pbnRlcjEg
U21hcnRQb2ludGVyMS5jeHggKQpUQVJHRVRfTElOS19MSUJSQVJJRVMoU21hcnRQb2ludGVyMSBJ
VEtDb21tb24pCgpBRERfRVhFQ1VUQUJMRShTbWFydFBvaW50ZXIyIFNtYXJ0UG9pbnRlcjIuY3h4
ICkKVEFSR0VUX0xJTktfTElCUkFSSUVTKFNtYXJ0UG9pbnRlcjIgSVRLQ29tbW9uKQo=
--00151758f83e2a300b047543d5e5
Content-Type: text/x-c++src; charset=US-ASCII; name="SmartPointer1.cxx"
Content-Disposition: attachment; filename="SmartPointer1.cxx"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_g0gnra2n0

I2luY2x1ZGUgIml0a09iamVjdC5oIgojaW5jbHVkZSAiaXRrT2JqZWN0RmFjdG9yeS5oIgoKbmFt
ZXNwYWNlIGl0awp7CgpjbGFzcyBBIDogcHVibGljIE9iamVjdAp7CnB1YmxpYzoKICB0eXBlZGVm
IEEgICAgICAgICAgICAgICAgICAgICAgICAgU2VsZjsKICB0eXBlZGVmIE9iamVjdCAgICAgICAg
ICAgICAgICAgICAgU3VwZXJjbGFzczsKICB0eXBlZGVmIFNtYXJ0UG9pbnRlcjxTZWxmPiAgICAg
ICAgUG9pbnRlcjsKICB0eXBlZGVmIFNtYXJ0UG9pbnRlcjxjb25zdCBTZWxmPiAgQ29uc3RQb2lu
dGVyOwoKICBpdGtOZXdNYWNybyhTZWxmKTsKcHJvdGVjdGVkOgogIEEoKSB7IHN0ZDo6Y291dCA8
PCAiQSBDb25zdHJ1Y3RvciIgPDwgc3RkOjplbmRsOyB9CiAgdmlydHVhbCB+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FNtYXJ0
UG9pbnRlcjxTZWxmPiAgICAgICAgUG9pbnRlcjsKICB0eXBlZGVmIFNtYXJ0UG9pbnRlcjxjb25z
dCBTZWxmPiAgQ29uc3RQb2ludGVyOwoKICBpdGtOZXdNYWNybyhTZWxmKTsKCiAgdm9pZCBTZXQo
IGNvbnN0IEEgKiBhICkKICAgIHsKICAgIHRoaXMtPm1fQSA9IGE7CiAgICB9CiAKICB2b2lkIFNl
dCggY29uc3QgQyAqIGMgKQogICAgewogICAgdGhpcy0+bV9DID0gYzsKICAgIH0KcHJvdGVjdGVk
OgogIEIoKSB7IHN0ZDo6Y291dCA8PCAiQiBDb25zdHJ1Y3RvciIgPDwgc3RkOjplbmRsOyB9CiAg
dmlydHVhbCB+QigpIHsgc3RkOjpjb3V0IDw8ICJCIERlc3RydWN0b3IiIDw8IHN0ZDo6ZW5kbDsg
fQoKcHJpdmF0ZToKICBBOjpDb25zdFBvaW50ZXIgICAgICBtX0E7CiAgQzo6Q29uc3RQb2ludGVy
ICAgICAgbV9DOwp9OwoKCn0KCmludCBtYWluKCkKewppdGs6OkE6OlBvaW50ZXIgYSA9IGl0azo6
QTo6TmV3KCk7Cml0azo6Qjo6UG9pbnRlciBiID0gaXRrOjpCOjpOZXcoKTsKaXRrOjpDOjpQb2lu
dGVyIGMgPSBpdGs6OkM6Ok5ldygpOwoKLy8gTGluawpiLT5TZXQoYSk7CmItPlNldChjKTsKYy0+
U2V0KGEpOwpjLT5TZXQoYik7CgpyZXR1cm4gRVhJVF9TVUNDRVNTOwp9Cg==
--00151758f83e2a300b047543d5e5
Content-Type: text/x-c++src; charset=US-ASCII; name="SmartPointer2.cxx"
Content-Disposition: attachment; filename="SmartPointer2.cxx"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_g0gnrv801

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