When some part of your app causes memory problems, the first thing I'd do is finding out which part, and which function is responsible for that. For this, first strip down your app until the problem goes away, then add function after function until the memory problem appears again.