How to know when to release an NSDate object?

Any or both of these date pointers require [release] when I am done with them. How do I know this? I am not sure, since I am not doing init explicitly.

NSDate *date = [NSDate date];

NSDate *date = [dateWithTimeIntervalSince1970:100000000];
+3
source share
2 answers

Both are auto-implemented, that is, you do not need to release them yourself. A rule of thumb is that you own the object if you send + alloc or -copy or explicitly save it:

  • [[SomeClass alloc] init ...]
  • [someObject copy]
  • [some object is saved]

If you have an object, you must free it. + new is a shortcut for + alloc and -init.

+5
source

, . , , , , , .

, , CARN. in Cocoa/Cocoa , Copy, Alloc, Retain New , , - . , , +1. , , "" , .

, .

+5

Source: https://habr.com/ru/post/1731217/


All Articles