[webkit-dev] PSA: Don't try to hold onto temporaries with references

Adam Barth abarth at webkit.org
Sun Oct 3 10:51:18 PDT 2010

On Sun, Oct 3, 2010 at 10:31 AM, Darin Adler <darin at apple.com> wrote:
> On Oct 3, 2010, at 2:21 AM, Adam Barth wrote:
>> If a function returns a temporary, you probably don't want to hold onto it with a "const Foo& foo".  The temporary will get deallocated
>> and then you'll be left with a reference to dead memory, which is bad new bears:
> I don’t understand why the crashes were happening here and why your code changes were helpful.
> What you say here about object lifetime is not correct. I thought the same thing a year or so back. But the C++ language keeps these objects alive until the end of the block. Some other programmers on the project challenged me when I made this assertion, and we found that I was wrong and they were right.
> But that doesn’t explain why the code was crashing!

Well, the tests are still crashing after these changes, so I'm
certainly willing to believe there's more going on here.  I'll keep


More information about the webkit-dev mailing list