Skip to content

Commit

Permalink
Make the string cache specific to each SBJsonStreamWriter, and make i…
Browse files Browse the repository at this point in the history
…t an NSCache rather than NSMutableDictionary so the OS can reclaim memory if necessary. Should fix #55
  • Loading branch information
stig committed Apr 27, 2011
1 parent 39d1f46 commit a93f424
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions Classes/SBJsonStreamWriter.h
Expand Up @@ -76,6 +76,7 @@
NSMutableData *data;
NSUInteger depth, maxDepth;
BOOL sortKeys, humanReadable;
NSCache *stringCache;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Classes/SBJsonStreamWriter.m
Expand Up @@ -33,7 +33,6 @@
#import "SBJsonStreamWriter.h"
#import "SBJsonStreamWriterState.h"

static NSMutableDictionary *stringCache;
static NSDecimalNumber *notANumber;

@implementation SBJsonStreamWriter
Expand All @@ -47,7 +46,6 @@ @implementation SBJsonStreamWriter

+ (void)initialize {
notANumber = [NSDecimalNumber notANumber];
stringCache = [NSMutableDictionary new];
}

#pragma mark Housekeeping
Expand All @@ -61,7 +59,9 @@ - (id)init {
NSAssert(states, @"States not initialised");

states[0] = [SBJsonStreamWriterStateStart sharedInstance];
}

stringCache = [[NSCache alloc] init];
}
return self;
}

Expand Down

0 comments on commit a93f424

Please sign in to comment.