From: William S F. <ws...@fu...> - 2006-04-21 23:28:36
|
John Pye wrote: > Hi all, > > I got a message like this from SCons: > dsg.i:356: Warning(473): Returning a pointer or reference in a director > method is not recommended. > > I was wondering if someone could briefly outline the reasoning there -- > is it broken, or it bad design to do this, or what? > Take a look at the C++ code generated. You'll see that the return value passed to C++ code points to a Python/Java object. There is no guarantee as to the lifetime of that object. If you are sure the object returned will not be garbage collected while the calling function is using it you should be okay. Be careful as gc happens in a second thread in Java, not sure about Python or Ruby. This is just a limitation of working with the target language and using pointers/references and is not easily solved. For example, you could modify the directorout typemap to take a copy of the object, but then you most likely have a memory leak on your hands or if you use a local static variable to copy the object, you'll end up with a thread safety issue. William |