Fix for runaway memory usage in BSJSONAdditions

17 views
Skip to first unread message

Jerry Krinock

unread,
Jan 30, 2011, 11:32:13 PM1/30/11
to BSJSONAdditions
I was getting "out of memory" errors (Note 1) when parsing a JSON
string of 440K characters. I fixed it by adding a local autorelease
pool in the implementation of -[NSScanner(BSJSONAdditions)
scanJSONObject:]. Specifically, in NSScanner+BSJSONAdditions, line
66, before the while(){} loop, add this line:

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init ] ;

and the, of course, after the while(){} loop, at line 75, add this
line:

[pool release] ;

Note 1: I thought that Mac OS X doesn't give "out of memory" errors,
just slows your system to a crawl as it uses gigabytes of virtual
memory, sometimes requiring a logout or restart if things get bad
enough. But there it was in the console, "Out of memory", several of
them! Maybe Apple has fixed this in a recent Snow Leopard update,
10.6.6?
Reply all
Reply to author
Forward
0 new messages