This is driving me crazy! I would really appreciate your help...
My app saves a .png (referencing a photo taken within the app) to a file in the iPhone Documents directory. The app then creates and displays a UIImage from the file with no issues - but only until the app is rerun an arbitrary number of times. I think this may be related to memory, because it functions correctly for longer on a G3 than it does a device with less memory. Regardless of device, although the .png file is still listed in the contents of the Documents directory - the same code suddenly will no longer create the UIImage. It returns a
Cannot access memory at address 0x0
message after some arbitrary number of runs. I have breakpoints set on
raise
didReceiveMemoryWarning (in the AppDelegate)
but they are not being invoked.
Here is some information from the debugger showing the Documents directory contents (including the .png) and showing the cannot access memory message I'm getting after several successful accesses...
(gdb) CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
<CFArray 0x41e0e10 [0x386e9f80]>{type = mutable-small, count = 4, values = (
0 : <CFString 0x41e0e70 [0x386e9f80]>{contents = "IMAGE_0001.PNG"}
1 : <CFString 0x41e0fa0 [0x386e9f80]>{contents = "IMAGE_0002.PNG"}
2 : <CFString 0x41e0e30 [0x386e9f80]>{contents = "IMAGE_0003.PNG"}
3 : <CFString 0x41e08a0 [0x386e9f80]>{contents = "Locations.sqlite"}
)}
(gdb) po [image filePath]
/var/mobile/Applications/2F6AB536-2CEB-4D1D-872E-87D2AF38C658/Documents/IMAGE_0001.PNG
/* code invoked */ photo = [[UIImage alloc] initWithContentsOfFile:image.filePath];
(gdb) po photo
Cannot access memory at address 0x0