J
Jarek Blakarz
Hi
I can read the following in the official documentation of boost shared_ptr:
"Because the implementation uses reference counting, cycles of shared_ptr
instances will not be reclaimed. For example, if main() holds a shared_ptr to
A, which directly or indirectly holds a shared_ptr back to A, A's use count
will be 2. Destruction of the original shared_ptr will leave A dangling with a
use count of 1."
I wrote the following example that in fact causes memory leak and not a
dangling pointer. Please provide me with an example of dangling pointer
described in the official boost documentation.
thanks.
struct A {
shared_ptr < A > a;
};
int main() {
shared_ptr<A> a (new A);
a->a = a;
return 0;
}
I can read the following in the official documentation of boost shared_ptr:
"Because the implementation uses reference counting, cycles of shared_ptr
instances will not be reclaimed. For example, if main() holds a shared_ptr to
A, which directly or indirectly holds a shared_ptr back to A, A's use count
will be 2. Destruction of the original shared_ptr will leave A dangling with a
use count of 1."
I wrote the following example that in fact causes memory leak and not a
dangling pointer. Please provide me with an example of dangling pointer
described in the official boost documentation.
thanks.
struct A {
shared_ptr < A > a;
};
int main() {
shared_ptr<A> a (new A);
a->a = a;
return 0;
}