热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

每个segue到模态vc的内存使用量都会增加-Memoryusageincreaseswitheveryseguetomodalvc

Ihavetwoviewcontrollers,oneisthetimelinethesecondoneisforthecreation.Inthatsecond

I have two view controllers, one is the timeline the second one is for the creation. In that second view controller I have a sub view. This sub view is an SKView. Now every time I segue to it, it increases the memory usage by 2mb (on a real device), but the memory usage stays the same when I unwind it.
So it is like this: I start with a usage of 12mb, then it gets 14-15mb. After the unwind it stays around 14-15mb. After the second segue to it, it becomes 17mb... and so on.

我有两个视图控制器,一个是第二个用于创建的时间线。在第二个视图控制器中,我有一个子视图。该子视图是SKView。现在,每当我使用它时,它会将内存使用量增加2mb(在真实设备上),但是当我放松它时,内存使用量会保持不变。所以它是这样的:我开始使用12mb,然后它得到14-15mb。放松后,它保持在14-15mb左右。在第二个到它之后,它变成17mb ......依此类推。

This is the code used in the timeline controller:

这是时间轴控制器中使用的代码:

@IBAction func createButtonAct(sender: AnyObject) {

    self.performSegueWithIdentifier("create", sender: self)


}

@IBAction func unwindFromCreation(segue: UIStoryboardSegue) {


}




// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "create"{
        let vc = segue.destinationViewController as! CreateViewController
        if vc.currCountry == nil || vc.currCountry != self.currCountry{
        vc.currCountry = self.currCountry
        }

    }


}

And this is the code in the create View Controller:

这是创建视图控制器中的代码:

class CreateViewController: UIViewController, UITextViewDelegate {

@IBOutlet weak var bubbleView: SKView!

@IBOutlet var arrow: UIButton!

var ref: Firebase!


let categories = CatsAndColors.categories


@IBOutlet var doneButton: UIButton!

@IBOutlet var titleField: UITextField!

@IBOutlet var descriptionView: KMPlaceholderTextView!

var choosedCat: String!

var selectedCats: NSMutableArray!

var currCountry:String!

var tap: UITapGestureRecognizer!

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(true)

    UIApplication.sharedApplication().statusBarStyle = .Default
    UIView.animateWithDuration(0.5, animations: { () -> Void in
        self.arrow.transform = CGAffineTransformMakeRotation(3.14159)
    })



    titleField.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged) 

    titleField.addTarget(self, action: "textFieldDidBegin:", forControlEvents: UIControlEvents.EditingDidBegin)

    titleField.addTarget(self, action: "textFieldDidEnd:", forControlEvents: UIControlEvents.EditingDidEnd)
    // the targets get removed in viewWillDisappear
    selectedCats = NSMutableArray()

}



override func viewDidLoad() {
    super.viewDidLoad()

    ref = Firebase(url: "https://blabber2.firebaseio.com")

    self.doneButton.enabled = false

    doneButton.setBackgroundImage(UIImage(named: "Done button inactive"), forState: .Disabled)

    doneButton.setTitleColor(UIColor(netHex: 0xF6F6F6), forState: .Disabled)

    doneButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)

    self.setupBubbles()

    self.descriptionView.delegate = self

}

func setupBubbles(){



    let floatingCollectiOnScene= ChooseBubblesScene(size: bubbleView.bounds.size)

    // floatingCollectionScene.scaleMode = .AspectFit


    /*let statusBarHeight = CGRectGetHeight(UIApplication.sharedApplication().statusBarFrame)
    let titleLabelHeight = CGRectGetHeight(self.tibleLabel.frame)*/

    bubbleView.presentScene(floatingCollectionScene)



    for (category, color) in categories {

        let node = ChooseBubbleNode.instantiate()
        node!.vc = self
        node!.fillColor = SKColor(netHex: color)
        node!.strokeColor = SKColor(netHex: color)
        node!.labelNode.text = category

        floatingCollectionScene.addChild(node!)

    }


}
...

And the catsAndColors struct looks like this:

而catsAndColors结构看起来像这样:

struct CatsAndColors{

static var categories = ["Crime":0x5F5068, "Travel":0xFBCB43, "Religion":0xE55555, "Tech":0xAF3151, "Economy":0x955BA5, "Games":0xE76851, "Climate":0x6ED79A, "Books":0xE54242, "History":0x287572, "Clothes":0x515151, "Sports":0x4AB3A7, "Food":0xD87171, "Politics":0x5FA6D6, "Music":0xDD2E63, "Tv-shows":0x77A7FB]

 }

2 个解决方案

#1


1  

Maybe you have created some sort of retain cycle between your view controllers.
If both view controllers hold a reference to each other, then try declaring one of the references as weak.

也许你已经在视图控制器之间创建了某种保留周期。如果两个视图控制器彼此保持引用,则尝试将其中一个引用声明为弱。

For more information on the topic read Resolving Strong Reference Cycles Between Class Instances.

有关主题的更多信息,请参阅解决类实例之间的强引用循环。

#2


0  

I solved the problem, it was strong reference in the sknode file.

我解决了这个问题,它是sknode文件中的强引用。

Thank you for your answers.

谢谢您的回答。


推荐阅读
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • 开发笔记:实验7的文件读写操作
    本文介绍了使用C++的ofstream和ifstream类进行文件读写操作的方法,包括创建文件、写入文件和读取文件的过程。同时还介绍了如何判断文件是否成功打开和关闭文件的方法。通过本文的学习,读者可以了解如何在C++中进行文件读写操作。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • SpringBoot uri统一权限管理的实现方法及步骤详解
    本文详细介绍了SpringBoot中实现uri统一权限管理的方法,包括表结构定义、自动统计URI并自动删除脏数据、程序启动加载等步骤。通过该方法可以提高系统的安全性,实现对系统任意接口的权限拦截验证。 ... [详细]
  • 本文介绍了一个Java猜拳小游戏的代码,通过使用Scanner类获取用户输入的拳的数字,并随机生成计算机的拳,然后判断胜负。该游戏可以选择剪刀、石头、布三种拳,通过比较两者的拳来决定胜负。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • C# 7.0 新特性:基于Tuple的“多”返回值方法
    本文介绍了C# 7.0中基于Tuple的“多”返回值方法的使用。通过对C# 6.0及更早版本的做法进行回顾,提出了问题:如何使一个方法可返回多个返回值。然后详细介绍了C# 7.0中使用Tuple的写法,并给出了示例代码。最后,总结了该新特性的优点。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
author-avatar
终渐疯分_501
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有