How can I solve these memory leak in xcode? - ios

I checked my application's memory leaking problem and these memory leaks are found.
How can I solve these memory leak?
I used Leaks tool in Instruments. Here are the screenshots
Screenshot 1
Screenshot 2

Switch to the Call Tree, select the options indicated in screenshot, then double click the code line.

Related

Memory leak in WkWebView instantiation

I have a Viewcontroller which contains wkwebview when I pop it from the navigation controller I get memory leak
The stack trace leads WkWebview instantiation
I am not using any delegates as well.
I am really wondering what causes this and how to fix this
It is not observed for a long time (at least I can't remember when I met it last time). Just tested in Xcode 11.2 / iOS 13.2. No leaks - neither in simple test project nor in Playground.
Thus, I assume it should be analysed real usage, which introduces leak.

Swift unbounded memory growth

I'm making a Swift 2.2 app in XCode7.3 using SpriteKit & GameCentre.
My issue is the memory used by the app continues to grow (an additional ~20MB is grabbed every second or so). Eventually this causes the app to crash due to memory issues. I get similar results running on a device (iPhone 6s) & simulator.
I've had a go at running it through Instruments (screenshot below) and this seems to show the issue.
Instruments screenshot
From digging into the instruments output, it seems to show a memory leak occurring off a 460 KiB malloc call. I haven't manage to isolate what's causing this from the stack trace.
Instruments output available - not certain how to attach it here. Any suggestions / pointers on where to start?
Try binary searching your code. Comment out half your calls. Still getting a memory leak? Ok, now you've reduced your search scope by half. Comment out half of the remainder. No memory leak? Great, you've just narrowed down your problem to 1 quarter of your code. Once you start getting the specific code that is causing the leak, you'll get much more useful answers out of StackOverflow.
Answer has been found - cause is a bug in the Apple/Spritekit code.
As part of setting up the scene I was setting showFields of the SKView to true. Once I disable this (false) the memory leak issue goes away.
From searching for this I found - https://forums.developer.apple.com/thread/27870

Why UILabel memory leak?

When I try to set text on label the memory usage increased. Why this happens?
In simulator awesome
XCode Version 5.1.1 (5B1008), ARC
[Resolved]
Not memory leak but my misunderstanding
The reason the memory usage is growing is because this tight loop is creating new string allocation. The device is never allow to exercise it retain cycle process.
youre stuck in a while loop m8
Edit: i realize you know this, but when are you going to need to dominate the main thread to set a uilabel

ios puzzle app crashes after a few rounds

I have an iPhone app, that seems to have memory leaking problem. It's a puzzle game, after a few puzzles, the app crashes on devices.
I'm now trying to use xcode Instruments to detect what's going on. First time to use Instruments.
I noticed a leak bar in the "Leaks" plot, right the time when the view is loaded:
What are these memory leaking objects, detected by xCode Instruments?
. However these leaked objects are small, so I guess my app has other problems.
When my app continues to run, usually for 10+ rounds on an iPad 2, it then crashes. I don't much about Instruments yet, so I watch "All Heap Allocations". At the beginning of first round puzzle, the column "# Overall" is ~70k, it grows slowly between rounds of puzzles. When a new round puzzle comes in, it goes to ~90k, then round by round it reaches ~200k, then crashes.
Before crashes, in the log console I see memory warning and "CONNECTION INTERRUPTED".
I've followed a few things after searching memory leaking, such set NSArray/NSDictionary or mutable ones to nil, as much as possible (although not all of them, since some go between puzzles). I also changed UIImage imageNamed to [UIIMage alloc] initWithContentOfFile.
What else should I look/check to see what causes memory problem? TIA!
EDIT:
I wish I could post some codes that may be the suspect, but I really don't know what part to post. I should've check via Instruments in the course developing, so that I would know what caused the problem.
Regarding other view controllers. I do have others (menu, settings, app-store-rate, etc) and I generated all of them via code. My app doesn't have a storyboard or nib file. When I test crashes, I just click Next Puzzle button, so all other views will not show at all. So, before crash, the only view shown is the main view, with a few button, a few subviews, an animated pictures (but only the first puzzle as introduction). If it helps, here is my app:
http://itunes.apple.com/us/app/wordsect/id599455449?ls=1&mt=8
If you trying to debug application with Instruments - enable zombie detection mode:
In
Xcode: Product->Scheme->Edit Scheme
Select Debug scheme
Select Arguments tab bar on the scheme description
In Environments variables add and check NSZombieEnabled variable
Then when you start application under Instruments control, you'll get name of the instance, when your application crashed.

Understanding xcode instruments for allocation

My assumption is that the red line is the culprit for why my object is still retained. Is that the case? Where can I go to find out more information about this line?
The red line is telling you that 90.4% of the memory allocated in the current method is allocated in the call to fadeOutSplash. Whether or not that line of code is causing your object to be retained can't be determined from the view in your screenshot.
If you look at the screenshot you can see an Info button next to the 90.4% listing. Clicking the button will show you the heaviest backtraces, the backtraces with the largest memory allocations. I'm not sure how much that information will help in your case, but it is additional information about that line of code.

Resources