Skip to content

Commit 4182183

Browse files
committed
Can now debug retain/release, in addition to add/removes
1 parent f63a111 commit 4182183

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

SSYDictionaryDebugger.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
#import <Cocoa/Cocoa.h>
22

3+
#if 0
4+
#warning Compiling with SSYDebuggingMutableDictionary
5+
#define SSY_DEBUGGING_MUTABLE_DICTIONARY_INCLUDED
6+
7+
// Set one or both of the following to 1
8+
#define SSY_DEBUGGING_MUTABLE_DICTIONARY_LOG_CONTENTS_CHANGED 0
9+
#define SSY_DEBUGGING_MUTABLE_DICTIONARY_LOG_MEMORY_MANAGEMENT 0
10+
11+
312

413
/*!
514
@brief A thin wrapper around NSMutableDictionary which may
615
be used in place of NSMutableDictionary when you want to have
7-
logged whenever the dictionary's contents are altered.
16+
logged whenever the dictionary's contents are changed, and/or
17+
to log memory management.
818

919
@details When using this class in place of NSMutableDictionary,
1020
you may get compiler warnings that SSYDebuggingMutableDictionary
1121
may not implement methods such as -count.&nbsp; Ignore those
12-
warnings.&nbsp; SSYDebuggingMutableDictionary will forward thoe
22+
warnings.&nbsp; SSYDebuggingMutableDictionary will forward those
1323
messages to the NSMutableDictionary that it wraps.
1424

1525
This class requires Mac OS 10.5 or later due to the use of
@@ -19,5 +29,7 @@
1929
{
2030
NSMutableDictionary* dic ;
2131
}
32+
2233
@end
2334

35+
#endif

SSYDictionaryDebugger.m

+53-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "SSYDictionaryDebugger.h"
22

3+
#ifdef SSY_DEBUGGING_MUTABLE_DICTIONARY_INCLUDED
34

45
@implementation SSYDebuggingMutableDictionary
56

@@ -10,10 +11,59 @@ - (id) init
1011
dic = [[NSMutableDictionary alloc] init] ;
1112

1213
}
14+
#if SSY_DEBUGGING_MUTABLE_DICTIONARY_LOG_MEMORY_MANAGEMENT
15+
NSLog(@"info %p has been initted", self) ;
16+
#endif
1317
return self;
1418
}
1519

20+
- (NSString*)description {
21+
return [dic description] ;
22+
}
23+
24+
- (id)forwardingTargetForSelector:(SEL)sel {
25+
return dic ;
26+
}
27+
28+
- (void)setValue:(id)value
29+
forUndefinedKey:key {
30+
[dic setValue:value
31+
forKey:key] ;;
32+
}
1633

34+
- (void)dealloc {
35+
#if SSY_DEBUGGING_MUTABLE_DICTIONARY_LOG_MEMORY_MANAGEMENT
36+
NSLog(@"info %p is being deallocced", self) ;
37+
#endif
38+
[dic release] ;
39+
40+
[super dealloc] ;
41+
}
42+
43+
#if SSY_DEBUGGING_MUTABLE_DICTIONARY_LOG_MEMORY_MANAGEMENT
44+
45+
- (id)retain {
46+
id x = [super retain] ;
47+
NSLog(@"info %p retained to %d by %@", self, [self retainCount], SSYDebugCaller()) ;
48+
return x ;
49+
}
50+
51+
- (id)autorelease {
52+
id x = [super autorelease] ;
53+
NSLog(@"info %p autoreleased by %@", self, SSYDebugCaller()) ;
54+
return x ;
55+
}
56+
57+
- (oneway void)release {
58+
NSInteger rc = [self retainCount] ;
59+
[super release] ;
60+
NSLog(@"info %p released fr %d by %@", self, rc, SSYDebugCaller()) ;
61+
}
62+
63+
#endif
64+
65+
66+
#if SSY_DEBUGGING_MUTABLE_DICTIONARY_LOG_CONTENTS_CHANGED
1767

1868
- (void)setValue:(id)value forKey:(NSString *)key {
1969
NSLog(@"12686-01 %s", __PRETTY_FUNCTION__) ;
@@ -45,18 +95,9 @@ - (void)setObject:(id)anObject forKey:(id)aKey{
4595
[dic setObject:anObject forKey:aKey] ;
4696
}
4797

48-
- (NSString*)description {
49-
return [dic description] ;
50-
}
51-
52-
- (id)forwardingTargetForSelector:(SEL)sel {
53-
return dic ;
54-
}
55-
56-
- (void)dealloc {
57-
[dic release];
98+
#endif
5899

59-
[super dealloc];
60-
}
61100

62101
@end
102+
103+
#endif

0 commit comments

Comments
 (0)