Domanda

I am testing an app under high memory pressure on iPad2. I am creating a series of pdf pages in a loop and debugging in Xcode i see the memory growing.

I have implemented the application and the controller related functions (didReceiveMemoryWarnings,applicationReceivedMemoryWarnings) and added an observer just before starting the loop:

    [[NSNotificationCenter defaultCenter] addObserver:self     selector:@selector(handleMemoryWarning:) name: UIApplicationDidReceiveMemoryWarningNotification object:nil];

Question #1: Those methods are never called and the app is terminated by Xcode with "memory pressure" notice. Did i miss any trigger? How could i have missed the warning before the system decided to close the app?

Question #2: The pdf context increases continuously, is there any way to check the size in bytes? (e.g. the NSData variable is not too big,~6MBytes but the memory in Xcode shows >200MBytes....how can i measure that?)

I was planning to flush the data to disk when a memory warnings comes up...but not warnings... :-(

Thanks!!!

È stato utile?

Soluzione

Don't keep the PDF in memory during creation and then try to flush. Instead, use CGPDFContextCreateWithURL so that only the 'current' page being created is in memory and each time you create a new page the data is pushed to disk. This will keep the memory usage to a minimum.

As for not receiving the notification, if your PDF generation is running synchronously on the main thread then the notification will never be posted (it will just be waiting on the queue to be processed).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top