I am making a program that strips out frames from a movie. This in Simulator of Xcode 5.0 on iOS 7. The number of objects I am trying to put in this array are 447. (Doesn't seem that many).
My program continuously crashes due to a memory leak either due to array size not being large enough?? (no idea if this statement is right) or due to something else. It consistently fails in the for loop only for vidoes whose number of frames are greater than 350. Less frame videos work fine.
Just a hunch could it have anything to do with the fact that I am storing large original frame images into an array? I am not scaling the frame pics down?
CODE:
NSMutableArray* allFrames = [[NSMutableArray alloc] init];
// get each frame
for (int k=0; k< totalFrames; k++)
{
int timeValue = timeValuePerFrame * k;
CMTime frameTime;
frameTime.value = timeValue;
frameTime.timescale = movie.duration.timescale;
frameTime.flags = movie.duration.flags;
frameTime.epoch = movie.duration.epoch;
CMTime gotTime;
CGImageRef myRef = [generator copyCGImageAtTime:frameTime actualTime:&gotTime error:nil];
[allFrames addObject:[UIImage imageWithCGImage:myRef]];
if (gotTime.value != frameTime.value)
NSLog (#"requested %lld got %lld for k %d", frameTime.value, gotTime.value, k);
//cleanup?
CFRelease(myRef);
}
ERROR:
2013-11-03 20:18:24.746 test[42139:a0b] requested 9925 got 9921 for k 397
2013-11-03 20:18:25.122 test[42139:a0b] requested 9950 got 9946 for k 398
everseHD(42046,0xb029b000) malloc: *** mmap(size=8298496) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2013-11-03 20:10:31.936 ReverseHD[42046:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x020305e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01db38b6 objc_exception_throw + 44
2 CoreFoundation 0x01fe2c3c -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x01fe28e0 -[__NSArrayM addObject:] + 64
4 ReverseHD 0x00003131 -[v1ViewController extractImagesFromMovie] + 3089
5 libobjc.A.dylib 0x01dc5874 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x00b27c8c -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x00b27c18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x00c1f6d9 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00c1fa9c -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x00c1e815 -[UIControl touchesBegan:withEvent:] + 254
11 UIKit 0x00b64efb -[UIWindow _sendTouchesForEvent:] + 386
12 UIKit 0x00b65d34 -[UIWindow sendEvent:] + 1232
13 UIKit 0x00b39a36 -[UIApplication sendEvent:] + 242
14 UIKit 0x00b23d9f _UIApplicationHandleEventQueue + 11421
15 CoreFoundation 0x01fb98af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x01fb923b __CFRunLoopDoSources0 + 235
17 CoreFoundation 0x01fd630e __CFRunLoopRun + 910
18 CoreFoundation 0x01fd5b33 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x01fd594b CFRunLoopRunInMode + 123
20 GraphicsServices 0x032239d7 GSEventRunModal + 192
21 GraphicsServices 0x032237fe GSEventRun + 104
22 UIKit 0x00b2694b UIApplicationMain + 1225
23 ReverseHD 0x0000244d main + 141
24 libdyld.dylib 0x02975725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Memory leak ⇒ lots of memory used
Lots of memory used ⇏ memory leak
You are correctly releasing myRef, which you own since it was created with a copy method, so the code you posted doesn't present any leak.
You are just using a lot of memory by trying to store 447 images.
Doesn't seem that many
is not a good evaluation. You should profile the application using Instruments with the Memory Allocation template and check for the size of the array, which is probably filling all the heap.
If you find out that the frames are too big to be stored in the array, you can reduce the size of the generated frame by using the maximumSize property of AVAssetImageGenerator, for instance
generator.maximumSize = CGSizeMake(320, 180);
As stated in the documentation:
The default value is CGSizeZero, which specifies the asset’s unscaled dimensions.
Related
What is happening?
I am getting an exception in a program where a function is to be called On a Button tap on a custom view within contentView of a UItableViewCell
What i have tried?
1) I tried to add a Global Exception point in the Breakpoints Navigator
2) Checked Zombie Detection from Instruments
3) Breakpoints in the functions that should be called
Crash Log that i receive?
-[UIImageView nextPage:]: unrecognized selector sent to instance 0xa7d5f20
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView nextPage:]: unrecognized selector sent to instance 0xa7d5f20'
*** First throw call stack:
(
0 CoreFoundation 0x023e11e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01fc98e5 objc_exception_throw + 44
2 CoreFoundation 0x0247e243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x023d150b ___forwarding___ + 1019
4 CoreFoundation 0x023d10ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x01fdb880 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x009463b9 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x00946345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x00a47bd1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00a47fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x00a47243 -[UIControl touchesEnded:withEvent:] + 641
11 UIKit 0x00cdc2e3 _UIGestureRecognizerUpdate + 7166
12 UIKit 0x00985a5a -[UIWindow _sendGesturesForEvent:] + 1291
13 UIKit 0x00986971 -[UIWindow sendEvent:] + 1021
14 UIKit 0x009585f2 -[UIApplication sendEvent:] + 242
15 UIKit 0x00942353 _UIApplicationHandleEventQueue + 11455
16 CoreFoundation 0x0236a77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x0236a10b __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x023871ae __CFRunLoopRun + 910
19 CoreFoundation 0x023869d3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x023867eb CFRunLoopRunInMode + 123
21 GraphicsServices 0x0381a5ee GSEventRunModal + 192
22 GraphicsServices 0x0381a42b GSEventRun + 104
23 UIKit 0x00944f9b UIApplicationMain + 1225
24 IslamBox 0x000029bc main + 76
25 libdyld.dylib 0x034b3701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
What else could i do as the functions are registered in the Nib file?
UPDATE: as the log says -[UIImageView nextpage] is unrecognized however the next page is in the ViewController. as the custom view is the ViewController's view added to the cell's contentView.
I need to retain my ViewController , or keep a strong reference to it if using ARC. If I assign it to cell.contentView as a local variable, it's not going to be around any more when nextPage: gets called. (The error shows that its memory has been released and re-used for a different type of object.)
Could it be just the fact that the object in your xib file is set as UIImageView instead of your own custom subclass of UIImageView ?
When the view is allocated from your xib, it will be a UIImageView. Having it linked to something different in your .h or .m won't change that.
Change it here :
if every time crash on [UIImageView nextPage:],
you can try
#implementation UIImageView(Test)
- (id)nextPage:(id)noUse
{
return nil;
}
#end
and set a breakpoint on the return.
int x = 5;
int t = 6;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"books.book", #"og:type",
#"www.goodreads.com", #"og:url",
#"Snow Crash", #"og:title",
#"978-3-16-148410-0",#"books:isbn",
#"http://en.wikipedia.org/wiki/File:Snowcrash.jpg", #"og:image",
#"www.google.com",#"og:audio:url",
#"www.facebook.com",#"al:windows_universal:url",
#"www.facebook.com",#"al:windows_phone:url",
#"www.facebook.com",#"al:windows:url",
#"www.facebook.com",#"al:iphone:url",
#"www.facebook.com",#"al:ipad:url",
x,#"books:rating:value",
t,#"books:rating:scale",
#"In reality, Hiro Protagonist delivers pizza for Uncle Enzo’s CosoNostra Pizza Inc., but in the Metaverse he’s a warrior prince. Plunging headlong into the enigma of a new computer virus that’s striking down hackers everywhere, he races along the neon-lit streets on a search-and-destroy mission for the shadowy virtual villain threatening to bring about infocalypse. Snow Crash is a mind-altering romp through a future America so bizarre, so outrageous…you’ll recognize it immediately.", #"og:description",
#"Science Fiction",#"books:genre",
#"eu_es",#"books:language:locale",
#[#"en_us",#"ca_es",#"cs_cz"],#"books:language:alternate",nil];
As you can see above I'm trying to create a Dictionary, however whenever i run the code i get error like this.
2014-06-11 23:50:50.338 TestApp[8374:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
*** First throw call stack:
(
0 CoreFoundation 0x00000001019ef495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010174e99e objc_exception_throw + 43
2 CoreFoundation 0x00000001019d27e3 +[NSDictionary dictionaryWithObjectsAndKeys:] + 1043
3 TestApp 0x000000010000724d -[CYCViewController postBooks:] + 1021
4 UIKit 0x00000001002fcf06 -[UIApplication sendAction:to:from:forEvent:] + 80
5 UIKit 0x00000001002fceb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
6 UIKit 0x00000001003d9880 -[UIControl _sendActionsForEvents:withEvent:] + 203
7 UIKit 0x00000001003d8dc0 -[UIControl touchesEnded:withEvent:] + 530
8 UIKit 0x0000000100333d05 -[UIWindow _sendTouchesForEvent:] + 701
9 UIKit 0x00000001003346e4 -[UIWindow sendEvent:] + 925
10 UIKit 0x000000010030c29a -[UIApplication sendEvent:] + 211
11 UIKit 0x00000001002f9aed _UIApplicationHandleEventQueue + 9579
12 CoreFoundation 0x000000010197ed21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
13 CoreFoundation 0x000000010197e5f2 __CFRunLoopDoSources0 + 242
14 CoreFoundation 0x000000010199a46f __CFRunLoopRun + 767
15 CoreFoundation 0x0000000101999d83 CFRunLoopRunSpecific + 467
16 GraphicsServices 0x0000000103b66f04 GSEventRunModal + 161
17 UIKit 0x00000001002fbe33 UIApplicationMain + 1010
18 TestApp 0x0000000100008153 main + 115
19 libdyld.dylib 0x00000001020875fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've followed solutions by adding NILbut still doesn't work. Everything is well placed. I checked and checked.
The values which can be nil in your dictionary are x and t. The above error says the object can't be nil, you can't put nil in place of an object of a key in a dictionary, instead you can try to put #"" or even you can supply [NSNull null].
Update
As you are trying to put
int x = 5;
int t = 6;
the above values are non-object values, a dictionary requires object, try put.
[NSNumber numberWithInt:x]
[NSNumber numberWithInt:t]
Attempting to remove an object at a NSMutableArray causes a crash:
2014-03-07 18:58:03.755 HomeWork Pro +[12637:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0xa2f4c20'
remove object code:
[hwArray removeObjectAtIndex:self.indexPath.row];
This only happens if I do it with self.indexPath.row, if I do it with a number it functions normally. I know the self.indexPath.row is not nil, I've NSlogged it to be sure and it turnde right. After doing that I do
[table reloadData]
to reload the UITableView data and the methods.
Any clue on what's the issue here?
Call stack
*** First throw call stack:
(
0 CoreFoundation 0x017aa5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0152d8b6 objc_exception_throw + 44
2 CoreFoundation 0x01847903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0179a90b ___forwarding___ + 1019
4 CoreFoundation 0x0179a4ee _CF_forwarding_prep_0 + 14
5 HomeWork Pro + 0x00006c88 -[HomeWork SelfDelete] + 216
6 HomeWork Pro + 0x0000711a -[HomeWork done:] + 618
7 libobjc.A.dylib 0x0153f874 -[NSObject performSelector:withObject:withObject:] + 77
8 UIKit 0x0029d0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
9 UIKit 0x0029d04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
10 UIKit 0x003950c1 -[UIControl sendAction:to:forEvent:] + 66
11 UIKit 0x00395484 -[UIControl _sendActionsForEvents:withEvent:] + 577
12 UIKit 0x00394733 -[UIControl touchesEnded:withEvent:] + 641
13 UIKit 0x002da51d -[UIWindow _sendTouchesForEvent:] + 852
14 UIKit 0x002db184 -[UIWindow sendEvent:] + 1232
15 UIKit 0x002aee86 -[UIApplication sendEvent:] + 242
16 UIKit 0x0029918f _UIApplicationHandleEventQueue + 11421
17 CoreFoundation 0x0173383f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x017331cb __CFRunLoopDoSources0 + 235
19 CoreFoundation 0x0175029e __CFRunLoopRun + 910
20 CoreFoundation 0x0174fac3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x0174f8db CFRunLoopRunInMode + 123
22 GraphicsServices 0x023349e2 GSEventRunModal + 192
23 GraphicsServices 0x02334809 GSEventRun + 104
24 UIKit 0x0029bd3b UIApplicationMain + 1225
25 HomeWork Pro + 0x00008bad main + 141
26 libdyld.dylib 0x02c8a70d start + 1
27 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
It looks to me like the crash message you posted and your stack trace do not match. The stack trace shows an "unrecognized selector" crash in the making, but the crash message shows that you were attempting to insert a nil object into an array.
Neither of those things matches the line of code that you posted. (removing an object from an array.) I guess you could get an unrecognized selector error from the line of source you posted if the array wasn't really a mutable array...
EDIT:
Based on your updated question, it's clear. Your array is not actually a mutable array even though you think it is.
Post the code that creates the array.
If you're copying it somewhere, look at that code carefully. If you're loading it from a plist or an archive, be aware that mutable arrays come back as immutable when you read them back in.
What you have is an immutable NSArray. What you want is an NSMutableArray, which actually does implement removeObjectAtIndex:. Make sure your array isn't getting replaced with an immutable version at some point.
I am trying to display a view that contains details of the user's account. Being fairly new to iOS development, the following code is what should work (based the docs and searches). Yet, the application crashes and I get a an error stating unrecognized selector:
2012-03-13 16:32:25.616 UrbanAgendaApp[4993:207] Displaying profile view
2012-03-13 16:32:25.635 UrbanAgendaApp[4993:207] -[UAFirstViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x4b45240
2012-03-13 16:32:25.674 UrbanAgendaApp[4993:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UAFirstViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x4b45240'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fbabe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0110f5c2 objc_exception_throw + 47
2 CoreFoundation 0x00fbc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f2c366 ___forwarding___ + 966
4 CoreFoundation 0x00f2bf22 _CF_forwarding_prep_0 + 50
5 UrbanAgendaApp 0x00002308 -[UAFirstViewController showProfileView] + 168
6 UrbanAgendaApp 0x00002254 -[UAFirstViewController myUaBtnTouch:] + 52
7 UIKit 0x00014a6e -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x000a31b5 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x000a5647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x000a41f4 -[UIControl touchesEnded:withEvent:] + 458
11 UIKit 0x000390d1 -[UIWindow _sendTouchesForEvent:] + 567
12 UIKit 0x0001a37a -[UIApplication sendEvent:] + 447
13 UIKit 0x0001f732 _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x00cbea36 PurpleEventCallback + 1550
15 CoreFoundation 0x00f9c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00efc6f7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00ef9983 __CFRunLoopRun + 979
18 CoreFoundation 0x00ef9240 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00ef9161 CFRunLoopRunInMode + 97
20 GraphicsServices 0x00cbd268 GSEventRunModal + 217
21 GraphicsServices 0x00cbd32d GSEventRun + 115
22 UIKit 0x0002342e UIApplicationMain + 1160
23 UrbanAgendaApp 0x00001c2a main + 170
24 UrbanAgendaApp 0x00001b75 start + 53
25 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
The method where this occurs is in a method in FirstViewController, which gets called as a result of a touch up event inside a button:
-(void)showProfileView {
NSLog( #"%#", #"Displaying profile view" ); // ***
UAProfileView *profileView = [[UAProfileView alloc] init];
[self presentViewController:profileView animated:TRUE completion:0];
}
This UAProfielView is a subclass of UIViewController and was was created along with an appropriate .xib file.
So the question is, how do I display this new view in my iPhone application? Using a storyboard is not an option because I have to support iOS 4.0.
The documentation for presentViewController:animated:completion: states that it is only supported on iOS 5.0 and up. You mentioned support for iOS 4.0.
Try presentModalViewController:animated: instead. Alternatively, use a nagivationController and do pushViewController:animated:
#Mike, make sure you connected the nib to the file's owner.
Presumably, the base class of UAFirstViewController is also UIViewController? Are you getting any warnings when you build?
I would personally use completion:nil, but I don't think that will make a difference.
So, if you are getting no warnings, then turn zombies on and see if you are dealing with a dead object. Instructions are here
How to enable NSZombie in Xcode?
Run the program and see if you get a zombie warning in the console. If that's the case, then the memory management is wrong.
If all of that is ok, post the code where you call showProfileView.
my application runs fine in my simulator but whenever i install it in the ipad
it receives SIGABRT and dies
2011-07-05 16:23:59.575 slots2[11008:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
*** Call stack at first throw:
(
0 CoreFoundation 0x3398964f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x321d5c5d objc_exception_throw + 24
2 CoreFoundation 0x338f1efd -[__NSArrayM insertObject:atIndex:] + 472
3 CoreFoundation 0x338f1d1b -[__NSArrayM addObject:] + 34
4 slots2 0x00005215 -[slots2ViewController viewDidLoad] + 420
5 UIKit 0x3485ef0f -[UIViewController view] + 110
6 slots2 0x00002d31 -[slots2AppDelegate application:didFinishLaunchingWithOptions:] + 92
7 UIKit 0x3485d821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
8 UIKit 0x34857b65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
9 UIKit 0x3482c7d7 -[UIApplication handleEvent:withNewEvent:] + 1114
10 UIKit 0x3482c215 -[UIApplication sendEvent:] + 44
11 UIKit 0x3482bc53 _UIApplicationHandleEvent + 5090
12 GraphicsServices 0x33bcde77 PurpleEventCallback + 666
13 CoreFoundation 0x33960a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
14 CoreFoundation 0x3396283f __CFRunLoopDoSource1 + 166
15 CoreFoundation 0x3396360d __CFRunLoopRun + 520
16 CoreFoundation 0x338f3ec3 CFRunLoopRunSpecific + 230
17 CoreFoundation 0x338f3dcb CFRunLoopRunInMode + 58
18 UIKit 0x34856d49 -[UIApplication _run] + 372
19 UIKit 0x34854807 UIApplicationMain + 670
20 slots2 0x00002c91 main + 88
21 slots2 0x00002c34 start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1 (8G4)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
(gdb)
but i m sure all files are there cuz same thing runs in simulator
the follwing array is the array which may be the problem
NSString *SubDir = [NSString stringWithFormat:#"/R/%d",Theme];
for(int i = 0;i<11;i++)
[SpinAnimationArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"blur%d",i] ofType:#"png" inDirectory:SubDir]]];
in slots2ViewController viewDidLoad
u have an array and u were trying to add object which has wrong index.
and checkout
blur0 - blur10 png is copied and existing in ur target