Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C - How to force low memory on iOS simulator

Tags:

memory

ios

I have an error that some users are having of EXC_BAD_ACCESS when their device is low on memory. The stack trace is pointing to the if line below, and I believe it's because of the UTF8String that's being deallocated and still being used:

dispatch_sync(dbQueue, ^{
    if (sqlite3_bind_text(sql_stmt, 1, pid.UTF8String, -1, SQLITE_STATIC) != SQLITE_OK) {
...

I'm having a hard time reproducing the issue on my end, how can I force or simulate low-memory on the simulator or a device?

Update:

I've tried adding a breakpoint to the line above, and then using the option Simulator -> Simulate Memory Warning, but I still can't reproduce the EXC_BAD_ACCESS error.

like image 952
heitortsergent Avatar asked Aug 07 '15 21:08

heitortsergent


People also ask

Does iOS simulator simulate performance?

The simulator does a really lousy job of indicating app performance. In fact it doesn't try. For most things the simulator is much, much faster than an iOS device. It runs your code on an x86 processor, which is much faster than the ARM and has many times more memory.

Where does the iPhone simulator store its data?

type: ~/Library/Application Support/iPhone Simulator.

How do I change the default location in iOS simulator?

in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly.


2 Answers

In the simulator there is a menu item: Hardware : Simulate Memory Warning

or

shiftcommandM

like image 197
zaph Avatar answered Oct 22 '22 10:10

zaph


In simulator's menu: Hardware-> Simulate Memory Warning.

Update

If you're sure that your app crashed at sqlite3_bind_text, I suppose the most potential problem could be that the pid.UTF8String is NULL sometimes in which case it causes crash. Additionally, it's not likely to be the case that pid or pid.UTF8String is deallocated when used, you can check the crash report (if you have any) and check the address of the memory which caused the EXC_BAD_ACCESS, for example if you have EXC_BAD_ACCESS CODE=2 ADDRESS=0x00000000, it means pid.UTF8String is indeed a NULL pointer, if the address is not 0x0, then, it's another problem (very unlikely in your case).

As a suggestion, please add nil check to your code:

if (pid) {
    if (sqlite3_bind_text(sql_stmt, 1, pid.UTF8String, -1, SQLITE_STATIC) != SQLITE_OK){
    // do your stuff
    }
} else {
    sqlite3_bind_null(sql_stmt,1);
}
like image 3
utogaria Avatar answered Oct 22 '22 12:10

utogaria