[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
The problem with NSUserDefaults
From: |
Derek Zhou |
Subject: |
The problem with NSUserDefaults |
Date: |
Tue, 15 Apr 2003 18:36:19 -0700 |
User-agent: |
Mutt/1.4i |
On Mon, Apr 14, 2003 at 08:57:21PM +0100, Richard Frith-Macdonald wrote:
>
> So it can tell if any defaults have been changed (in which it should
> update itsself
> by sending an notification to every registered observer). If I
> remember correctly
> it should actually stat the defaults database to see if it has been
> modified at 30
> second intervals, and only read it if it has changed.
Actually, it will sync with the database twice in 30 seconds intervals.
Believe it or not, there is one ghost NSUserDefaults hanging somewhere,
beside the shared one that everybody use. This is true for almost
every GNUStep applicaiton, using AppKit or not.
I spend 2 hours last night trying to understand the code. Basically, it
has two problems:
1, It has circular references. It has a NSTimer and the timer retains it.
2, It does not have any api to break this circular reference. Not even the
+resetStandardUserDefaults method break it.
So it can never get fully released. This doesn't seem like a big problem,
however, during the construction phase of the shared defaults, it create
a temp one. And the temp one doesn't get released, nor does its timer
(because it can't).
The other consequence of this problem is the main runloop will never stop
gracefully. From the document for NSRunLoop: "(-run will) runs the loop
in DefaultRunLoopMode by repeatedly invoking runModeBeforeDate
until all input sources have been removed." But there will always be two
timers. NSApplication.m calls exit(0) to quit, which is not graceful.
What if the app is doing some non-blocking file writing?
Derek