Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Posted 18 April 2013 - 12:27 PM

Do it the first way.  The pointer returned by GetResource is going to be different for each call (as GetResource is called on a different shader resource each time), so by doing it the second way you'll (1) leak the resource returned by your first GetResource call, (2) actually destroy the resource returned by your second, and (3) risk crashing when you come to clean up the second for real.


Posted 18 April 2013 - 12:24 PM

Either way will work as all that GetResource does is increment a reference count, and all that Release (in this context) does is decrement the same reference count: there's no resource creation or destruction going on here.  So long as you match the number of Release calls to the number of GetResource calls your code is valid and you won't leak anything.


Conceptually it's the same as this:




Versus this:


RefCount -= 2;


Having said that, the first approach seems more robust to me as keeping the Release as close to the GetResource as possible means that you're less likely to forget the Release.