Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Leak







   Are destructors always run (or run in the same way if called
explicitly by the programmer or by the OS itself)?  If so, it would
seem like any delay the destructors take to run would happen no
matter whether the programmer explicitly clean up the objects
or just
lets the OS do it anyway.  Unless the OS runs the destructors in the
background and so doesn't block the user interface, whereas the
program would appear to hang while it calls them in the main thread
before releasing the UI.

I don't know in detail what is happening "under the covers". I can only
provide this anecdote that describes some observed behaviour:


We had a large, complex (unnecessarily so in both cases, I believe) C++
project, that we built cross-platform (OSX, Linux, win32).


On exit, the original author had written the code such that it
*explicitly* called the destructors for all the widgets he'd created.
When the user clicked the exit button, the app would take 20~30 seconds
to close, and at least one of the CPU's would max out during this time.
The code was modified to *not* explicitly call the destructors.
Thereafter, when the user clicked the exit button, the app would
terminate "straight away", with no CPU maxing out.



I don't know why anyone would ever want or need to *explicitly* call destructors for objects. I'm not saying there's never a reason to, but I've never done it in all my years of programming C++. Destructors are called automatically for you when objects are destroyed (either by going out of scope or by explicitly deleting them via pointers). Perhaps the problem lies in this fact itself, in that destructors are being called explicitly AND they're being called automatically when the objects are destroyed?


-Howard


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >Re: Memory Leak (From: "MacArthur, Ian (SELEX GALILEO, UK)" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.