xref: /llvm-project/clang/docs/analyzer/checkers/dealloc_example.m (revision 1a17032b788016299ea4e3c4b53670c6dcd94b4f)
1*1a17032bSKristof Umann
2*1a17032bSKristof Umann
3*1a17032bSKristof Umann@interface MyObject : NSObject {
4*1a17032bSKristof Umann  id _myproperty;
5*1a17032bSKristof Umann}
6*1a17032bSKristof Umann@end
7*1a17032bSKristof Umann
8*1a17032bSKristof Umann@implementation MyObject // warn: lacks 'dealloc'
9*1a17032bSKristof Umann@end
10*1a17032bSKristof Umann
11*1a17032bSKristof Umann@interface MyObject : NSObject {}
12*1a17032bSKristof Umann@property(assign) id myproperty;
13*1a17032bSKristof Umann@end
14*1a17032bSKristof Umann
15*1a17032bSKristof Umann@implementation MyObject // warn: does not send 'dealloc' to super
16*1a17032bSKristof Umann- (void)dealloc {
17*1a17032bSKristof Umann  self.myproperty = 0;
18*1a17032bSKristof Umann}
19*1a17032bSKristof Umann@end
20*1a17032bSKristof Umann
21*1a17032bSKristof Umann@interface MyObject : NSObject {
22*1a17032bSKristof Umann  id _myproperty;
23*1a17032bSKristof Umann}
24*1a17032bSKristof Umann@property(retain) id myproperty;
25*1a17032bSKristof Umann@end
26*1a17032bSKristof Umann
27*1a17032bSKristof Umann@implementation MyObject
28*1a17032bSKristof Umann@synthesize myproperty = _myproperty;
29*1a17032bSKristof Umann  // warn: var was retained but wasn't released
30*1a17032bSKristof Umann- (void)dealloc {
31*1a17032bSKristof Umann  [super dealloc];
32*1a17032bSKristof Umann}
33*1a17032bSKristof Umann@end
34*1a17032bSKristof Umann
35*1a17032bSKristof Umann@interface MyObject : NSObject {
36*1a17032bSKristof Umann  id _myproperty;
37*1a17032bSKristof Umann}
38*1a17032bSKristof Umann@property(assign) id myproperty;
39*1a17032bSKristof Umann@end
40*1a17032bSKristof Umann
41*1a17032bSKristof Umann@implementation MyObject
42*1a17032bSKristof Umann@synthesize myproperty = _myproperty;
43*1a17032bSKristof Umann  // warn: var wasn't retained but was released
44*1a17032bSKristof Umann- (void)dealloc {
45*1a17032bSKristof Umann  [_myproperty release];
46*1a17032bSKristof Umann  [super dealloc];
47*1a17032bSKristof Umann}
48*1a17032bSKristof Umann@end
49*1a17032bSKristof Umann
50