[webkit-dev] Naked new considered harmful

Darin Adler darin at apple.com
Tue Aug 24 11:14:20 PDT 2010


Thanks, Adam. This project will be worthwhile.

I think we may want to write a document about this that goes alongside <http://webkit.org/coding/RefPtr.html> because I’m sure there will be frequently-asked questions.

On Aug 24, 2010, at 10:46 AM, Adam Barth wrote:

> In the cases where we have an intentional memory leak (e.g., for a static), please use the leakPtr() member function to document the leak.

This means that we might have code that looks like this:

    static NiftyNonRefCountedObject* singleNeverToBeDeletedInstance = adoptPtr(new NiftyNonRefCountedObject).leakPtr();

Then later, we could refactor it to look like this:

    static NiftyNonRefCountedObject* singleNeverToBeDeletedInstance = NiftyNonRefCountedObject::create().leakPtr();

These changes will make leaks and double deletion mistakes less likely.

    -- Darin



More information about the webkit-dev mailing list