Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI/C++  RSS feed

 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this questions is more of a C++ questions but I'm using it in conjunction with JNI, so hopefully someone here can answer this. Is it bad practice to return an object that was created with new from a method since that would leave the object that called the method responsible for deleting the new object? Or am I missing something...

Thanks,
Jeff
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In C++ development, whenever you return a pointer, you have to document who (caller or callee) owns it, then make sure that call-sites abide by that. Providing you do that, I don't think it is bad practice.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your meaining your new'ed C++ object is staying C++ side you can use auto ptr's and smart ptr's to gain that lovely Java garbage collector effector (auto ptr is in the C++ STL not sure if smart pointers made it into STL years since I did that much C++ but msdn had an implementation that was portable).

If you wree referring to a Java new'ed object now owned in C++ you've got minor issues with garbage collector but I'll assume you menat the first.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!