Memory warning/performance issues - ios

iOS 6 SDK. Xcode 4.5.
Using storyboard and arc. I am making an application that consists of a number of calculators that compute various formulas. On one scene, I'm using 8 UIButtons that have a PNG file as a background image, and they are labelled as different formula categories to allow the user to navigate to 8 different formulas which are contained in 8 different scenes.
I'm using modal segues and am utilizing the [self.presenting dismissViewController] method to dismiss each scene. That all works fine.
On one calculator in particular, I've set up the scene to resemble an actual calculator. I used a UIImageView with a UILabel on top of it to act like a display. Even without code attached to it, when running on my device, I notice that the transition gets hung up when segueing to that scene. I'm not sure why. Also, whenever I hit a button I get a receives memory warning in the console. I'm also showing a leak in instruments.
This app works perfectly in the simulator but not on the actual phone. I'm not sure what's wrong. Could it be my compiler settings? Or is it the fact that I'm not programmatically setting up the button images? Even when there is just a UIImage with a blue picture PNG and a label on top of it, no buttons or a viewcontroller for this view, it still gets hung up.
I'd appreciate any tips or tutorials or just plain tell me what I'm doing wrong lol.
Thanks.

I found out what was wrong. I was using a very high resolution image on each of those buttons. When I replaced it with a low resolution image the memory issue went away

Related

UINavigationBAr Title as an Image, used to work, doesn't display anymore in XCode9

I'm having a small annoying issue, I'm using storyboards on this app since it's creation, I want to make an update to it and something that used to work before doesn't anymore
See I was using an image as a UINavigationBar Title, Dragged it to the storyboard and it worked almost automatically,
Now well the image doesn't display anymore... Here's a screen :
As you Can see, the UIImageView is there, but nothing shows up. and when I run the app, still nothing...
I'd like to solve it trought Storyboards, but my knowledge is limited
thanks

Sporadic black screen when performing segue in iOS 9.2.1 / XCode 7.2

Upvoters: can you let me know if you've seen this problem as well?
The issue I'm seeing occurs roughly every 1 in 15 times when I try to modally launch a view controller from a button on a certain scene.
This is done with iOS 9.2.1 and XCode 7.2, though it is not clear which versions it happens on. It's not easy to change the iOS version down.
The symptoms are as follows:
The destination view controller is not visible on the phone. Instead, the top bar (the one with the carrier) goes black, and sometimes it flickers so the whole screen is completely black. The launching view controller is visible, but not responsive.
When this happens, I go to the XCode screen and do view debugging. Remarkably, this shows the destination screen, almost as it's supposed to look. The only difference is that one of the views has not done its drawRect, and one of the other views looks all speckled. But of course it does not at all correspond to what the phone is showing.
The cancel button on the destination screen seems to still work, because when I press where it's supposed to be, the app continues to function. If I try to relaunch the screen with the button, it again doesn't work though. So once this has happened, the screen has stopped working for that session and the app needs to be killed and restarted.
There are not many hints, but this information may help:
There's 3 scrollviews containing views on the destination screen. All three child views have their own drawRect. It turns out one of the drawRects is not called when the error occurs, resulting in the grey background being shown. The speckled view does run, but I have no clue why it looks like that in view debugging.
No warnings in XCode. Nothing about NSLayout constraints or presentations overlapping.
Two fields are set on the destination view controller on the prepareForSegue function.
The segue is launched from the times button by way of the storyboard. There's no missing or extra outlet, and it is named correctly for the prepare function to catch it.
The issue is sporadic, but will reliably occur if you launch/cancel many times in a row.
Here are the screen grabs. I won't show you the black screen. It's just black with the carrier and the time.
I've solved it. Checking the memory usage turned out to be quite useful.
The grey area was supposed to be filled by a large background with lines drawn. It turns out the naive implementation of drawBackground causes the memory size to balloon to over 200MB. I replaced it with a CSTiledLayer, and now it takes a few MB instead.

iOS Swift 2.0 UITextView freezes app depending on text

I'm experiencing a weird issue with my Swift 2.0 app.
I have a (editable) UITextView defined in my storyboard.
If I leave the text property empty in the storyboard everything is working as expected. But when I enter the text Kaasje (in the storyboard and recompiling), the app freezes when loading the nib (navigating through segue) and the CPU jumps to 100% (the app remains stuck).
The app will never reach viewDidLoad at this point.
It makes no difference when changing between fonts or fontsizes, behavior remains.
Pausing in Xcode does not leave me with anything useful, the main thread is busy without specifying any function. Nothing is logged to output nor any logs are created.
I'm running iOS9 on a iPad Air, the app has a built target of iOS8 and runs landscape-only.
Has anyone ever experienced anything like this before, and might have an explanation for this behaviour?
As far as my assumptions: Something goes wrong when calculating the text-size which results in a infinite loop while either calculating the size or adjusting the frame.
P.S. It happens with other texts too, but "Kaasje" always fails. It seems to fail when the the text is only 1 line. Longer texts tend to succeed aswel as leaving it empty.
As suggested in the comments there seems to be a bug in Xcode 7 in combination with iOS9.
I ended up recreating the entire view, the problem did not occur again.

iOS Launch Screen Image not always showing

I use a Launch Screen (xib) in my app to overcome the problem of the resizeable screen, since i don't always want add Launchscreens everytime, Apple create a new iPhone with a different screen resolution.
In my launchscreen, i placed a UIImageView directly in the center of the view using constraints. The image shows the logo of the company i work for.
The problem is, that sometimes the image is being hidden (mostly after install and first launch) and sometimes it shows (mostly after a view times using it). I'm not quite sure, what the problem is. Is it because at the first-launch-time(s) it has to load many ressources?
Figured out the problem: It seems, that if there isn't enough disc space left on the device, it doesn't show the xib's (Launch-Screen's) Image. iOS at some point clears out some disc-space (i guess from NSLibraryDirectory) and than the images show again.
If this is a major problem to any of your apps, use Launch-Images instead.

iPad performance issues

I have this problem with performance of my iPad app..
For developing, I use MonoDevelop, which takes care of Garbage collecting. Still my questions are rather generic, I'd say.
OK, I use TabBarController with 5 NavigationControllers. Inside nav controllers there are some controllers, whose views are TableViews or ScrollViews. Next child is always just regular view.
I have a few questions:
1) TableViews never scroll smoothly. I have some alpha transparency, but since I did my graphics in Photoshop and not programmatically, this transparency should not cause much problems. It doesn't matter whether I have few or many results in table.
On the other hand, I have ScrollView which serves same purpose, i.e. to be a table with different layout and buttons have Photoshop generated transparency as well. It works perfectly.
For tables I applied DequeueReusableCell() which works fine (I see that memory usage is not increasing after scrolling). So why would tables scroll so jerky?
2) My app supports rotation. When I scroll table or scrollView and simultaneously tilt the device a bit, I get maybe 1 or 2 FPS. What is the best way to implement rotation? As I understand, ShouldAutorotateToInterfaceOrientation has to be overridden in all controllers in NavigationController chain. Also, I need to add observer in View I want some changes to happen. Do I have to use BeginGeneratingDeviceOrientationNotifications() in all views or is it enough to do it in Main.cs? Maybe this slows it down?
3) After some time app starts getting memory warnings and then crashes eventually. I tried to read logs and run app with Instruments, but can't find the cause of crash.
4) What exactly happens to a View popped from NavigationController stack? I can't reuse it. But could it be that Monotouch (or me) doesn't dispose it correctly?
I have almost same app for iPhone without support for rotation which never crashes. I think I'm doing something wrong with this rotation, but I'm not sure what.
Any help will be appreciated the most. So, thank you in advance.
Regards
1 - transparencies are always a problem. Even if you're not rendering the images in code, the phone still needs to do the compositing of the image, and that may take a lot of time. UITableViews have to calculate the final composite image every time a new cell is displayed, or the table is scrolled, while UIScrollViews can calculate only once, since the image won't change. So be very careful about it, turn the transparency off, and check if performance improves.
2 - You shouldn't need to notify every uiview in your application. Receive the notification in the controllers that you want to update only, like for example if you want to rearrange items in the UIViewControllers view.
3 - you have one (or many) memory leaks. My guess is that MonoTouch probably can't garbage collect UIViews or UIViewControllers, because they're still being linked from somewhere in UIKit, like a UINavigationController
4 - UIViews are not disposed by UIKit until the app gets a memory warning notification.
Like Eduardo said, alpha transparency in Views comes at a price. There are some tools that you can use to identify the bottlenecks discussed in these WWDC 2011 talks from:
https://developer.apple.com/videos/wwdc/2011/
iOS Performance and Power Optimization with Instruments
Understanding UIKit Rendering
In the "Debug" menu of the iOS simulator you can find various debugging tools that will color different regions of the screen indicating where some problematic rendering is taking place. The WWDC 2011 talks show what you can do to fix those problems.
For your memory problems, it is very likely that you have something pointing out to your objects around, so you need to make sure those objects are gone. While we currently are not shipping our new profiler for MonoTouch that can show the source of the problem, I wrote a "poor man's" debug utility that will help you narrow down which objects are alive. It is available here:
http://tirania.org/tmp/HttpDebug.cs
Call HttpDebug.Start () from your application and as you run, connect with a web browser to http://localhost:5000 to get a list of live Objective-C objects surfaced to C#. The tool is not perfect and shows a lot of irrelevant data, but it would at least give you an idea of what is going on.

Resources