LWN.net Logo

freeing resources

freeing resources

Posted Feb 11, 2008 3:26 UTC (Mon) by pflugstad (subscriber, #224)
In reply to: It's not a mistake to ban goto... it's not a mistake to keep it... by filipjoelsson
Parent article: Interview: Mark "Markey" Kretschmann (Not the Gentoo Weekly News)

Are you looking for RAII?

I use it quite often for things like mutexes, but it can be used in many other situations - any time you hold a resource in a function that must be cleaned up when the function exits, including when throwing an exception.

It's a fairly common design pattern for C++ these days - I think I started seeing it a year or two ago...


(Log in to post comments)

freeing resources

Posted Feb 11, 2008 8:19 UTC (Mon) by nix (subscriber, #2304) [Link]

In C++ it's probably two decades old: I know it was landing in published 
textbooks ten years ago.

I didn't see it in C outside the Linux kernel before about 2004.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds