Question: Could someone explain to a C++ programmer most important differences between Java (and C# as well) references and shared\_ptr (from Boost or from C++0x).

I more or less aware how shared\_ptr is implemented. I am curious about differences in the following ares:

1) Performance.
2) Cycling. shared\_ptr can be cycled (A and B hold pointers to each other). Is cycling possible in Java?
3) Anything else?

Thank you.

Answer: 
**Performance**: `shared_ptr` performs pretty well, but in my experience is slightly less efficient than explicit memory management, mostly because it is reference counted and the reference count has to allocated as well. How well it performs depends on a lot of factors and how well it compares to Java/C# garbage collectors can only be determined on a per use case basis (depends on language implementation among other factors).

**Cycling** is only possible with `weak_ptr`, not with two `shared_ptr`s. Java allows cycling without further ado; its garbage collector will [break the cycles](https://stackoverflow.com/questions/176745/circular-references-in-java). My guess is that C# does the same.

**Anything else**: the object pointed to by a `shared_ptr` is destroyed as soon as the last reference to it goes out of scope. The destructor is called immediately. In Java, the finalizer may not be called immediately. I don't know how C# behaves on this point.
Cyclical references with C++ reference-counted pointers will not be disposed. You can use weak pointers to work around this. Cyclical references in Java or C# may be disposed, when the garbage collector feels like it.

When the count in a C++ reference-counted pointer drops to zero, the destructor is called. When a Java object is no longer reachable, its finalizer may not be called promptly or ever. Therefore, for objects which require explicit disposal of external resources, some form of explicit call is required.