Detecting cycles at run time is expensive and rarely worth the effort. It is much better to have a clear understanding of your data structure and awareness of where cycles could arise and then break them using Boost.weak_ptr, as weak_ptr was created to deal with exactly this problem. For instance, if you have a tree that needs parent to child and child to parent links, then you can use shared_ptr in the parent class and weak_ptr in the child struct. The important thing is to be clear on the ownership semantics. There are so many possibilities that it's hard to be more specific without a lot of detail. At 12:01 PM 2/9/2009, you wrote:
I have recently started using boost::shared_ptr in my code. I understand that cycles of shared_ptr will cause a problem. Now, I strongly believe that such a situation has arisen in my code and am wondering if there is any advice/tips on how one can detect when a cycles of shared_ptr has occured. The code I am working on is developed by several people and the shared_ptr of interest is passed to many objects.