[swift-users] Why does this leak?

Rick Aurbach rlaurb at icloud.com
Tue Mar 28 14:22:51 CDT 2017

This is getting interesting.

I added your suggested test code (set to execute once):
class FontSelectorDialog : UITableViewController {

	static let chooser : ColorChooser = ColorChooser()
	override func viewDidAppear(_ animated: Bool) {
		FontSelectorDialog.chooser.textChooserType = .text

	< . . . >

BY THE WAY — I didn’t think to mention this previously, but the “leaking” code is in a framework and I put the suggested test code in the same framework.

Using Xcode 8.3:

(1) Running Simulator for iPhone 7+ (10.3), profiling the code, neither your suggested test code NOR the original code shows a leak in the Leaks Instrument.

(2) Running on an iPad Air 2 (10.2), profiling the code, your suggested test code does NOT show a leak, but the original code DOES. (The stack trace for the leak point is at the bottom of this email.)

I haven’t taken the next step of attempting to build a simple example to see if I can duplicate the problem in a simple project. I’d like to pursue this because it is increasingly looking like a “not my” bug, and I’d like to prevent others from spending as much time on this issue as I have already.


Rick Aurbach

> On Mar 28, 2017, at 4:14 AM, Alex Blewitt <alblue at apple.com> wrote:
>> On 28 Mar 2017, at 05:41, Rick Aurbach <rlaurb at icloud.com> wrote:
>> That wouldn’t work directly. The “leak” occurs when processing a segue called in response to a user button push. (I suppose I could attempt to wire up a UI Test, but would rather not go down that route.)
>> What I can try is to see if I can create a simple, artificial example. If it also reports a leak, then I could try looping it. I’ll look into it in the morning.
> You could try doing something like:
> static let choser:ColorChoser = ColorChoser()
> choser.textChoserType = .text
> Run that in Xcode and see if it shows a leak.
> Alex

   0 libsystem_malloc.dylib malloc_zone_malloc
   1 libsystem_malloc.dylib malloc
   2 libswiftCore.dylib swift_slowAlloc
   3 libswiftCore.dylib _swift_allocObject_
   4 libswiftCore.dylib _swift_allocObject_
   5 RLAFontSelector specialized RLAFontSelectorDialog.prepare(for : UIStoryboardSegue, sender : Any?) -> () /Users/rlaurb/Projects/RLAFontSelector/Sources/RLAFontSelectorDialog.swift:0
   6 RLAFontSelector RLAFontSelectorDialog.prepare(for : UIStoryboardSegue, sender : Any?) -> () /Users/rlaurb/Projects/RLAFontSelector/Sources/RLAFontSelectorDialog.swift:0
   7 RLAFontSelector @objc RLAFontSelectorDialog.prepare(for : UIStoryboardSegue, sender : Any?) -> () /Users/rlaurb/Projects/RLAFontSelector/Sources/RLAFontSelectorDialog.swift:0
   8 UIKit -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:]
   9 UIKit -[UIStoryboardSegueTemplate _perform:]
  10 UIKit -[UIStoryboardSegueTemplate perform:]
  11 UIKit -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
  12 UIKit -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
  13 UIKit _runAfterCACommitDeferredBlocks
  14 UIKit _cleanUpAfterCAFlushAndRunDeferredBlocks
  15 UIKit _afterCACommitHandler
  17 CoreFoundation __CFRunLoopDoObservers
  18 CoreFoundation __CFRunLoopRun
  19 CoreFoundation CFRunLoopRunSpecific
  20 GraphicsServices GSEventRunModal
  21 UIKit -[UIApplication _run]
  22 UIKit UIApplicationMain
  23 PoetsCorner main /Users/rlaurb/Projects/PoetsCorner/PoetsCorner/SettingsController.swift:13
  24 libdyld.dylib start

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170328/4f34585e/attachment.html>

More information about the swift-users mailing list