Skip to content

Commit 74fa686

Browse files
committed
Convert all library code to use Automatic Reference Counting (ARC)
1 parent e8b2537 commit 74fa686

15 files changed

+35
-84
lines changed

Changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# JSON Framework Changes
22

3+
## Version 3.1 (TBD)
4+
5+
* [Issue 79][#79]: Memory management is hard. Converted project to use Automatic Reference Counting (ARC).
6+
37
## Version 3.0 (June 18th, 2011)
48

59
* Bump version number

Classes/NSObject+SBJson.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3434
@implementation NSObject (NSObject_SBJsonWriting)
3535

3636
- (NSString *)JSONRepresentation {
37-
SBJsonWriter *writer = [[[SBJsonWriter alloc] init] autorelease];
37+
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
3838
NSString *json = [writer stringWithObject:self];
3939
if (!json)
4040
NSLog(@"-JSONRepresentation failed. Error is: %@", writer.error);
@@ -48,7 +48,7 @@ - (NSString *)JSONRepresentation {
4848
@implementation NSString (NSString_SBJsonParsing)
4949

5050
- (id)JSONValue {
51-
SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
51+
SBJsonParser *parser = [[SBJsonParser alloc] init];
5252
id repr = [parser objectWithString:self];
5353
if (!repr)
5454
NSLog(@"-JSONValue failed. Error is: %@", parser.error);

Classes/SBJsonParser.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ - (id)init {
4444
return self;
4545
}
4646

47-
- (void)dealloc {
48-
[error release];
49-
[super dealloc];
50-
}
5147

5248
#pragma mark Methods
5349

@@ -58,12 +54,12 @@ - (id)objectWithData:(NSData *)data {
5854
return nil;
5955
}
6056

61-
SBJsonStreamParserAccumulator *accumulator = [[[SBJsonStreamParserAccumulator alloc] init] autorelease];
57+
SBJsonStreamParserAccumulator *accumulator = [[SBJsonStreamParserAccumulator alloc] init];
6258

63-
SBJsonStreamParserAdapter *adapter = [[[SBJsonStreamParserAdapter alloc] init] autorelease];
59+
SBJsonStreamParserAdapter *adapter = [[SBJsonStreamParserAdapter alloc] init];
6460
adapter.delegate = accumulator;
6561

66-
SBJsonStreamParser *parser = [[[SBJsonStreamParser alloc] init] autorelease];
62+
SBJsonStreamParser *parser = [[SBJsonStreamParser alloc] init];
6763
parser.maxDepth = self.maxDepth;
6864
parser.delegate = adapter;
6965

Classes/SBJsonStreamParser.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ - (id)init {
5757
return self;
5858
}
5959

60-
- (void)dealloc {
61-
self.error = nil;
62-
self.state = nil;
63-
[stateStack release];
64-
[tokeniser release];
65-
[super dealloc];
66-
}
67-
6860
#pragma mark Methods
6961

7062
- (NSString*)tokenName:(sbjson_token_t)token {

Classes/SBJsonStreamParserAccumulator.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@ @implementation SBJsonStreamParserAccumulator
3333

3434
@synthesize value;
3535

36-
- (void)dealloc {
37-
[value release];
38-
[super dealloc];
39-
}
4036

4137
#pragma mark SBJsonStreamParserAdapterDelegate
4238

4339
- (void)parser:(SBJsonStreamParser*)parser foundArray:(NSArray *)array {
44-
value = [array retain];
40+
value = array;
4541
}
4642

4743
- (void)parser:(SBJsonStreamParser*)parser foundObject:(NSDictionary *)dict {
48-
value = [dict retain];
44+
value = dict;
4945
}
5046

5147
@end

Classes/SBJsonStreamParserAdapter.m

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ - (id)init {
5959
return self;
6060
}
6161

62-
- (void)dealloc {
63-
[keyStack release];
64-
[stack release];
65-
[super dealloc];
66-
}
6762

6863
#pragma mark Private methods
6964

@@ -116,7 +111,7 @@ - (void)parser:(SBJsonStreamParser*)parser found:(id)obj {
116111

117112
- (void)parserFoundObjectStart:(SBJsonStreamParser*)parser {
118113
if (++depth > self.levelsToSkip) {
119-
dict = [[NSMutableDictionary new] autorelease];
114+
dict = [NSMutableDictionary new];
120115
[stack addObject:dict];
121116
currentType = SBJsonStreamParserAdapterObject;
122117
}
@@ -128,27 +123,25 @@ - (void)parser:(SBJsonStreamParser*)parser foundObjectKey:(NSString*)key_ {
128123

129124
- (void)parserFoundObjectEnd:(SBJsonStreamParser*)parser {
130125
if (depth-- > self.levelsToSkip) {
131-
id value = [dict retain];
126+
id value = dict;
132127
[self pop];
133128
[self parser:parser found:value];
134-
[value release];
135129
}
136130
}
137131

138132
- (void)parserFoundArrayStart:(SBJsonStreamParser*)parser {
139133
if (++depth > self.levelsToSkip) {
140-
array = [[NSMutableArray new] autorelease];
134+
array = [NSMutableArray new];
141135
[stack addObject:array];
142136
currentType = SBJsonStreamParserAdapterArray;
143137
}
144138
}
145139

146140
- (void)parserFoundArrayEnd:(SBJsonStreamParser*)parser {
147141
if (depth-- > self.levelsToSkip) {
148-
id value = [array retain];
142+
id value = array;
149143
[self pop];
150144
[self parser:parser found:value];
151-
[value release];
152145
}
153146
}
154147

Classes/SBJsonStreamWriter.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ - (id)init {
8383
return self;
8484
}
8585

86-
- (void)dealloc {
87-
self.error = nil;
88-
self.state = nil;
89-
[stateStack release];
90-
[super dealloc];
91-
}
92-
9386
#pragma mark Methods
9487

9588
- (void)appendBytes:(const void *)bytes length:(NSUInteger)length {

Classes/SBJsonStreamWriterAccumulator.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ - (id)init {
4242
return self;
4343
}
4444

45-
- (void)dealloc {
46-
[data release];
47-
[super dealloc];
48-
}
4945

5046
#pragma mark SBJsonStreamWriterDelegate
5147

Classes/SBJsonTokeniser.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ - (id)init {
5050
return self;
5151
}
5252

53-
- (void)dealloc {
54-
[_stream release];
55-
[super dealloc];
56-
}
5753

5854
- (void)appendData:(NSData *)data_ {
5955
[_stream appendData:data_];
@@ -164,7 +160,7 @@ - (sbjson_token_t)getStringToken:(NSObject**)token {
164160
return sbjson_token_string;
165161

166162
} else {
167-
acc = [[string mutableCopy] autorelease];
163+
acc = [string mutableCopy];
168164
}
169165
}
170166

Classes/SBJsonUTF8Stream.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ - (id)init {
4444
return self;
4545
}
4646

47-
- (void)dealloc {
48-
[_data release];
49-
[super dealloc];
50-
}
5147

5248
- (void)appendData:(NSData *)data_ {
5349

@@ -90,7 +86,7 @@ - (BOOL)getSimpleString:(NSString **)string {
9086
case '"':
9187
case '\\':
9288
case 0 ... 0x1f:
93-
*string = [[[NSString alloc] initWithBytes:(_bytes + start) length:(_index - start) encoding:NSUTF8StringEncoding] autorelease];
89+
*string = [[NSString alloc] initWithBytes:(_bytes + start) length:(_index - start) encoding:NSUTF8StringEncoding];
9490
return YES;
9591
break;
9692
default:
@@ -135,7 +131,7 @@ - (BOOL)skipCharacters:(const char *)chars length:(NSUInteger)len {
135131
}
136132

137133
- (NSString*)stringWithRange:(NSRange)range {
138-
return [[[NSString alloc] initWithBytes:_bytes + range.location length:range.length encoding:NSUTF8StringEncoding] autorelease];
134+
return [[NSString alloc] initWithBytes:_bytes + range.location length:range.length encoding:NSUTF8StringEncoding];
139135

140136
}
141137

Classes/SBJsonWriter.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,11 @@ - (id)init {
5252
return self;
5353
}
5454

55-
- (void)dealloc {
56-
[error release];
57-
[super dealloc];
58-
}
5955

6056
- (NSString*)stringWithObject:(id)value {
6157
NSData *data = [self dataWithObject:value];
6258
if (data)
63-
return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
59+
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
6460
return nil;
6561
}
6662

@@ -80,9 +76,9 @@ - (NSString*)stringWithObject:(id)value error:(NSError**)error_ {
8076
- (NSData*)dataWithObject:(id)object {
8177
self.error = nil;
8278

83-
SBJsonStreamWriterAccumulator *accumulator = [[[SBJsonStreamWriterAccumulator alloc] init] autorelease];
79+
SBJsonStreamWriterAccumulator *accumulator = [[SBJsonStreamWriterAccumulator alloc] init];
8480

85-
SBJsonStreamWriter *streamWriter = [[[SBJsonStreamWriter alloc] init] autorelease];
81+
SBJsonStreamWriter *streamWriter = [[SBJsonStreamWriter alloc] init];
8682
streamWriter.sortKeys = self.sortKeys;
8783
streamWriter.maxDepth = self.maxDepth;
8884
streamWriter.humanReadable = self.humanReadable;

SBJson.xcodeproj/project.pbxproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@
729729
buildSettings = {
730730
ALWAYS_SEARCH_USER_PATHS = NO;
731731
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
732+
CLANG_ENABLE_OBJC_ARC = YES;
732733
COPY_PHASE_STRIP = NO;
733734
CURRENT_PROJECT_VERSION = 31;
734735
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -751,6 +752,7 @@
751752
buildSettings = {
752753
ALWAYS_SEARCH_USER_PATHS = NO;
753754
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
755+
CLANG_ENABLE_OBJC_ARC = YES;
754756
COPY_PHASE_STRIP = YES;
755757
CURRENT_PROJECT_VERSION = 31;
756758
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -817,10 +819,11 @@
817819
buildSettings = {
818820
ALWAYS_SEARCH_USER_PATHS = NO;
819821
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
822+
CLANG_ENABLE_OBJC_ARC = YES;
820823
DSTROOT = /tmp/sbjson_ios.dst;
821824
GCC_PRECOMPILE_PREFIX_HEADER = YES;
822825
GCC_PREFIX_HEADER = "sbjson-ios/sbjson-ios-Prefix.pch";
823-
GCC_VERSION = com.apple.compilers.llvmgcc42;
826+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
824827
HEADER_SEARCH_PATHS = (
825828
include/,
826829
"$(BUILT_PRODUCTS_DIR)/usr/local/lib/include/",
@@ -841,10 +844,11 @@
841844
buildSettings = {
842845
ALWAYS_SEARCH_USER_PATHS = NO;
843846
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
847+
CLANG_ENABLE_OBJC_ARC = YES;
844848
DSTROOT = /tmp/sbjson_ios.dst;
845849
GCC_PRECOMPILE_PREFIX_HEADER = YES;
846850
GCC_PREFIX_HEADER = "sbjson-ios/sbjson-ios-Prefix.pch";
847-
GCC_VERSION = com.apple.compilers.llvmgcc42;
851+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
848852
HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/include/";
849853
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
850854
OTHER_LDFLAGS = "-ObjC";
@@ -861,13 +865,14 @@
861865
buildSettings = {
862866
ALWAYS_SEARCH_USER_PATHS = NO;
863867
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
868+
CLANG_ENABLE_OBJC_ARC = YES;
864869
FRAMEWORK_SEARCH_PATHS = (
865870
"$(SDKROOT)/Developer/Library/Frameworks",
866871
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
867872
);
868873
GCC_PRECOMPILE_PREFIX_HEADER = YES;
869874
GCC_PREFIX_HEADER = "sbjson-iosTests/sbjson-iosTests-Prefix.pch";
870-
GCC_VERSION = com.apple.compilers.llvmgcc42;
875+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
871876
INFOPLIST_FILE = "sbjson-iosTests/sbjson-iosTests-Info.plist";
872877
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
873878
OTHER_LDFLAGS = (
@@ -886,13 +891,14 @@
886891
buildSettings = {
887892
ALWAYS_SEARCH_USER_PATHS = NO;
888893
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
894+
CLANG_ENABLE_OBJC_ARC = YES;
889895
FRAMEWORK_SEARCH_PATHS = (
890896
"$(SDKROOT)/Developer/Library/Frameworks",
891897
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
892898
);
893899
GCC_PRECOMPILE_PREFIX_HEADER = YES;
894900
GCC_PREFIX_HEADER = "sbjson-iosTests/sbjson-iosTests-Prefix.pch";
895-
GCC_VERSION = com.apple.compilers.llvmgcc42;
901+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
896902
INFOPLIST_FILE = "sbjson-iosTests/sbjson-iosTests-Info.plist";
897903
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
898904
OTHER_LDFLAGS = (

Tests/JsonTestCase.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ - (void)setUp {
4141
writer = [[SBJsonWriter alloc] init];
4242
}
4343

44-
- (void)tearDown {
45-
[parser release];
46-
[writer release];
47-
}
48-
4944
- (NSString*)otherFileName {
5045
return @"output";
5146
}

Tests/ProxyTest.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ @interface Bool : NSObject
5555

5656
@implementation Bool
5757
- (id)proxyForJson {
58-
return [NSArray arrayWithObjects:[[True new] autorelease], [[False new] autorelease], nil];
58+
return [NSArray arrayWithObjects:[[True alloc] init], [[False alloc] init], nil];
5959
}
6060
@end
6161

@@ -76,11 +76,7 @@ @interface ProxyTest : SenTestCase {
7676
@implementation ProxyTest
7777

7878
- (void)setUp {
79-
writer = [SBJsonWriter new];
80-
}
81-
82-
- (void)tearDown {
83-
[writer release];
79+
writer = [[SBJsonWriter alloc] init];
8480
}
8581

8682
- (void)testUnsupportedWithoutProxy {

Tests/WriterTest.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ @interface WriterTest : SenTestCase {
3939
@implementation WriterTest
4040

4141
- (void)setUp {
42-
writer = [SBJsonWriter new];
43-
}
44-
45-
- (void)tearDown {
46-
[writer release];
42+
writer = [[SBJsonWriter alloc] init];
4743
}
4844

4945
- (void)testInfinity {
@@ -73,7 +69,7 @@ - (void)testTimeInterval {
7369

7470

7571
- (void)testWriteToStream {
76-
SBJsonStreamWriter *streamWriter = [[[SBJsonStreamWriter alloc] init] autorelease];
72+
SBJsonStreamWriter *streamWriter = [[SBJsonStreamWriter alloc] init];
7773

7874
STAssertTrue([streamWriter writeArray:[NSArray array]], nil);
7975

0 commit comments

Comments
 (0)