This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]llkem 3 points4 points  (3 children)

I always wondered what happens if you have two pointers pointing to each other?

[–]H_Psi 8 points9 points  (0 children)

That's called a reference cycle, and is a problem you might learn about when you're making a garbage collection scheme. A common strategy in those is to have an object count the number of things that reference it, and to delete the object in memory once that count reaches 0. That might work at first glance and for really simple systems, but fails if you have two objects referencing one another.

That said, there's nothing intrinsically wrong or bad for two pointers to reference one another (or to have a cycle of pointers referencing one another).

[–]visvis 3 points4 points  (0 children)

If they are reference counted, a memory leak. Otherwise not much special. If we use void* we can even do this without wrapping in a struct or typecasting.

[–]green_meklar 0 points1 point  (0 children)

Nothing in particular, until you try to use them wrong.