FROM : Ken Thomases
DATE : Mon Mar 24 21:12:12 2008
On Mar 23, 2008, at 8:55 PM, Samvel wrote:
> I have defined class (say, Download) that uses NSURLConnection to
> download something from internet. My application is Cocoa with UI.
> I want to call:
>
> [Download cancel]
>
> and wait for notification from this class once user quits
> application. Reasoning: my Download class should cancel connection
> and perform some operations before object can be released in
> program. Thus I can not simply deallocate Download instance in
> dealloc method.
>
> So, the idea is: instead of calling [myDownload cancel] from
> dealloc method delay application quit until all steps are completed
> in Download. Thus call [myDownload cancel] and wait for
> Notification say DownloadCanceled. Only then deallocate object.
>
> Is there any way to figure out when user initiated quit
> application? How to delay it?
>
> I think there should be something pretty much similar to
> awakeFromNib but called at the very end upon application quit.
What Sherm told you is correct. However, I think this is largely
unnecessary.
When an application quits, it does _not_ properly release all of your
objects. Thus, their dealloc methods are generally not called. This
is a deliberate optimization since there's no point in manually
cleaning up the process memory. The kernel will completely eliminate
the process address space (and do other cleanup) when the process
exits. The TCP socket underlying the NSURLConnection will be closed,
too.
Some things may need to be cleaned up, like a temp file holding the
data for the in-progress download. For that, you can probably simply
remove the file immediately at the point of
applicationWillTerminate:. There's no need to delay the quitting in
that case.
Cheers,
Ken
DATE : Mon Mar 24 21:12:12 2008
On Mar 23, 2008, at 8:55 PM, Samvel wrote:
> I have defined class (say, Download) that uses NSURLConnection to
> download something from internet. My application is Cocoa with UI.
> I want to call:
>
> [Download cancel]
>
> and wait for notification from this class once user quits
> application. Reasoning: my Download class should cancel connection
> and perform some operations before object can be released in
> program. Thus I can not simply deallocate Download instance in
> dealloc method.
>
> So, the idea is: instead of calling [myDownload cancel] from
> dealloc method delay application quit until all steps are completed
> in Download. Thus call [myDownload cancel] and wait for
> Notification say DownloadCanceled. Only then deallocate object.
>
> Is there any way to figure out when user initiated quit
> application? How to delay it?
>
> I think there should be something pretty much similar to
> awakeFromNib but called at the very end upon application quit.
What Sherm told you is correct. However, I think this is largely
unnecessary.
When an application quits, it does _not_ properly release all of your
objects. Thus, their dealloc methods are generally not called. This
is a deliberate optimization since there's no point in manually
cleaning up the process memory. The kernel will completely eliminate
the process address space (and do other cleanup) when the process
exits. The TCP socket underlying the NSURLConnection will be closed,
too.
Some things may need to be cleaned up, like a temp file holding the
data for the in-progress download. For that, you can probably simply
remove the file immediately at the point of
applicationWillTerminate:. There's no need to delay the quitting in
that case.
Cheers,
Ken
| Related mails | Author | Date |
|---|---|---|
| Samvel | Mar 24, 02:55 | |
| Sherm Pendley | Mar 24, 04:24 | |
| Samvel | Mar 24, 04:36 | |
| Sherm Pendley | Mar 24, 04:42 | |
| Ken Thomases | Mar 24, 21:12 | |
| James Hober | Mar 25, 17:26 | |
| Steve Bird | Mar 25, 17:34 | |
| j o a r | Mar 25, 17:44 | |
| James Hober | Mar 25, 23:19 | |
| j o a r | Mar 25, 23:26 |






Cocoa mail archive

