0

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.

9891541
  • 251
  • 3
  • 14

2 Answers2

1

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:].

justin
  • 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
  • I wouldn't assume it would leak… – justin Feb 17 '12 at 05:25
0

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.

Jeshua Lacock
  • 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