views:

249

answers:

2

Hi all,

I've been able to replicate a bug consistently on an iPhone app I'm working on. The bug always follows as soon as my UIViewController's didReceiveMemoryWarning method gets invoked. Some of the issues I'm seeing are as follows:

  • UITextField's text property niling out.
  • The previous data in the UITextField is getting appended to a string multiple times, thus giving me corrupted data back when I HTTP to the server

This happens as soon as my breakpoint on didReceiveMemoryWarning hits, otherwise all appears to be working just excellent. My question is, does it sound normal for this odd behavior to occur during a memory leak? If so, what is happening with the UIViewController that's causing such ad-hoc duplication of data in a previous UITextField (which is a part of a UITableViewCell's contentView, so I figure there's some oddity going on with dequeueing of the cell)

It's interesting none the less.

Thanks!

+1  A: 

When the iPhone runs low on memory the OS tries to intelligently do things to reduce memory overhead. In a few cases I've seen this cause odd behavior such as text content go missing or a keyboard failing to display.

However you may want to focus on finding the source of your memory problems instead of the results.

Andrew Grant
A: 

Usually, not very much, as long as your application is not using all the memory in the hardware. But memory leaks can stack up, and next thing you know you are out of physical RAM. You may see a sudden performance dip as virtual memory kicks in and parts of your app starting paging to the much slower flash disk storage. This is when your controller will likely get a low memory warning, and UIKit may remove some things it thinks you don't need (like views without superviews, possibly other thigns). Soon after that, the entire app will crash as the iPhone OS forces it to quit because it is using too much memory.

The short version: memory leaks lead to crashes. But the removal of object it thinks you dont need may cause some odd behavior as well.

Squeegy
iPhone's virtual memory manager does not swap to disk. When you are out of physical RAM, you are out of luck. That's why the OS sends a memory warning in the first place.
benzado