Release between parent and a child

Member
Posts: 306
Joined: 2009.03
Post: #1
When should a child be let go. If you let them go, if they come back it wa... nevermind.. anyhow. Consider this

Classes A,B,C

B and C form a parent child relationship. B and C retain each other.
A has a pointer to b(the parent). A is destroyed and in its dealloc it releases B.
Problem here is that you orphaned the code but they each refer to each other so their refrence count doesn't hit 0. Is the solution here to not have children retain on their parents? Granted I could see situations where its not clear which is a parent, like using 3rd party libraries and such. So whats the general rule for these sorts of situations?

Thanks.

On further thinking I remembered the idea of weak refrences, which I googled, and its as I said above, just hold pointer no retain. In my code its obvious who is the parent. But I could see it not being obvious at times. Anyhow all is good. But since I made this thread, a quick question on instruments. I tracked down a bunch of memory leaks. Great!
However there is one that happens right at startup that has none of my code in the stack trace.
Here is a copy from instruments.

20 libSystem.B.dylib thread_start
19 libSystem.B.dylib _pthread_start
18 libGLProgrammability.dylib glvmPreInit
17 libGLProgrammability.dylib glvmBuildModularFunctionDeferred
16 libGLProgrammability.dylib glvmBuildFPTransformFunction
15 libGLProgrammability.dylib glvmGenerateModularFunctionPointer
14 libGLProgrammability.dylib glvmGenerateModularFunctionPointer
13 libGLProgrammability.dylib glvmGenerateModularFunctionPointer
12 libGLProgrammability.dylib glvmOptimizeModularFunction
11 libGLProgrammability.dylib glvmOptimizeModularFunction
10 libGLProgrammability.dylib glvmOptimizeModularFunction
9 libGLProgrammability.dylib PPStreamParamBindingIsEqual
8 libGLProgrammability.dylib PPStreamParamBindingIsEqual
7 libGLProgrammability.dylib PPStreamParamBindingIsEqual
6 libGLProgrammability.dylib PPStreamParamBindingIsEqual
5 libGLProgrammability.dylib PPParserGetErrorString
4 libGLProgrammability.dylib PPParserGetErrorString
3 libGLProgrammability.dylib PPParserGetErrorString
2 libGLProgrammability.dylib glvmGenerateModularFunctionPointer
1 libstdc++.6.dylib operator new(unsigned long)
0 libSystem.B.dylib malloc

Does anyone have an idea what that is about, and what I might do about it?
Thanks.
Quote this message in a reply
Post Reply