dateWithTimeIntervalSince1970 vs. CFDateCreate:
The first one (dateWithTimeIntervalSince1970) creates and object, returns it to you, and "autoreleases" it - that is, adds it to an autorelease pool which usually gets drained at the end of the current event. That object will probably be gone by the time you go to use it, since you did not retain it.
CFDateCreate creates an object that you own - it will not be destroyed until you release it. You never do release it, even in your setStaticDate method, which is why it leaks. More on this later.
+load vs +initialize
Cocoa with love says "Any class can have a +(void)load method and it will be invoked by the runtime when the class is loaded. For normal compiled classes, this occurs during "image loading" (some time before main() is invoked)." This means that the "+load" method may be called before the execution of your program's main function, therefore before any autorelease pool is created. So you can't use an method (like dateWithTime) that requires an autorelease pool in place. The +initialize is called much later, after execution has started but before any messages are sent to this object. You almost surely want initialize.
Your setters
Your setters are not retaining the new object and releasing the old one, so you're going to leak memory every time they're called. You need to release the old object so it can be destroyed if appropriate, and retain the new one so it is not destroyed until you're done with it. A properly written setter might look like this:
Code:
+ (void) setStaticDate:(NSDate *) newDate {
NSDate *oldValue = staticDate; //keep a pointer to the old value
staticDate = [newDate retain]; //retain and assign the new value
[oldValue release]; //release the old value
}
Extra credit
Someone else may stroll by and say "don't do what you're doing, use a singleton" and they might be right - your use of class methods and static variables means you lose out on properties and key-value coding and archiving and some other nice stuff. However your code is pretty clear and it's obvious what it does. The
code for a singleton is less obvious, and requires more knowledge of Cocoa internals to understand. Still, you might want to look at it in the future.