Fixing a memory leak, and guarding against arbitrarily large window size causing large allocation

Open to a cleaner solve on the allocation issue. Trying to create a NSData that is almost 2 gigs is guaranteed to fail on iOS.