In my app i tried to create [NSData initWithContentsOfFile]. In ios4(ipod gen 3) nsdata created without error. But in ios5(ipod gen 4) application crashed. I thinks ipod 4 have 512mb of RAM while ipod 3 is 256mb, so why cannot create data.
-
have you looked at the crash logs? – Daniel A. White Feb 17 '12 at 02:09
-
You mean it crashed when you had double RAM? – mbh Feb 17 '12 at 02:14
-
Daniel : The size about ~70mb. But this is my test case. Because the application run on ios5 and gets memory warning then crash. So i want to test limit memory by load file. – 9891541 Feb 17 '12 at 02:21
-
mbh : yeah! I used instruments to view memory allocation. My app run about 30mb. Sometimes when process actions memory increase to ~70mb.And crash with ios5 :( – 9891541 Feb 17 '12 at 02:25
-
It sounds like you might have a memory leak. – Hot Licks Feb 17 '12 at 02:39
-
Maybe. But i want to know why limit memory in ios 5 is smaller than ios 4(with same kind of device ipod) – 9891541 Feb 17 '12 at 02:48
-
Current iPod Touch models only have 256 MB of memory. The iPad 2 and iPhone 4S have 512 MB. – Feb 17 '12 at 03:12
-
Really? I think ipod 4 have 512mb of ram memory. – 9891541 Feb 17 '12 at 03:26
2 Answers
It's a constraint for a reason -- the resources you want just do not fit well with the system's design.
See if you can mmap the file instead. man mmap
NSData
also supports mapping a file using custom read options, See +[NSData dataWithContentsOfFile:options:error:]
.

- 104,054
- 14
- 179
- 226
-
Sorry. Not clear about man map. But i used fread to read data of image(3k x 2k).Too large but ipod3 run without error. And i have management memory in best way i known. Create NSData is my test case to test limit memory. – 9891541 Feb 17 '12 at 03:23
-
Ah. I known NSData supports mapping a file. But did you use mapped file with [NSData getBytes]? I assume that makes leak memory. Anyway i created an object MyData and used fread to read data page by page. Thanks! – 9891541 Feb 17 '12 at 03:52
-
Just because a device has more RAM does not mean you will automatically get more RAM available in your app. iOS uses memory as efficiently as possible, and there are a number of reasons why it may crash on your iOS 5 device, for instance iOS 5 likely uses more RAM than iOS 4. Next, did you have the same amount of open/backgrounded apps running on both devices? You can also tell how much memory is free/available to your app using the Instruments. Keep an eye on that. If you run out of memory the only solution is to use less memory.

- 5,730
- 1
- 28
- 58
-
Ipod3 have more app run on background than Ipod4. My app loads images with size 3k * 2k. So the memory available is ~30mb. When process an action likes save to photo album, memory increases to ~70mb, receive memory warning and crash. – 9891541 Feb 17 '12 at 03:28
-
Yup. ~70mb is definitely asking for a crash - on either device. Guess you are just more lucky on the iPod 3. – Jeshua Lacock Feb 17 '12 at 03:43
-
:D. Maybe! http://stackoverflow.com/questions/6044147/memory-limit-and-ios-memory-allocation-in-iphone-sdk. Anyway i make my app avoid large data input. Thanks! – 9891541 Feb 17 '12 at 03:46
-
Yeah, precisely, that answer states "Apple your app risks being shut down for memory usage when you use more than 20mb of ram". So you might get away with more - but there is no guarantee. And I have never been able to use 180mb on my iPad 2. – Jeshua Lacock Feb 17 '12 at 03:51
-
Absolutely! But i want to compare between two device ipod3 and ipod4. Because ipod4 gets double RAM memory and cannot run my app :D. – 9891541 Feb 17 '12 at 03:56
-
The answer is you are simply using too much memory to be safe on both. I would recommend tiling the image in at least two tiles. – Jeshua Lacock Feb 17 '12 at 04:05
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7829/discussion-between-user565247-and-jeshua-lacock) – 9891541 Feb 17 '12 at 04:18