gpt4 book ai didi

ios - Xcode 9 : Getting More Information On Memory Leak

转载 作者:行者123 更新时间:2023-11-30 11:13:03 27 4
gpt4 key购买 nike

在了解到内存泄漏可能是导致我的 iOS 应用程序在安装到手机上数小时后崩溃的原因后,我观看并阅读了有关内存泄漏的视频/文章,特别是在 Xcode 中以及如何调试它们。我一直在尝试使用内存调试器和 Xcode 泄漏工具,但没有成功。我想知道如何找到泄漏源?我所附的屏幕截图显示了众多泄漏之一,它永远不会让我比图片显示的内容更深入。在视频中,Xcode 使用回溯将它们带到导致问题的代码行,但在任何情况下我都无法做到这一点。我还注意到泄漏来自 UIKIT,这正常吗?感谢您的帮助,因为我对 Xcode 还很陌生。

Here is the image.

这是我最初登录 View Controller 的一些代码。在第二张图片中,您会看到唯一存在内存泄漏的 View 是这个 View - 我也无法深入研究这一点。 Second image of memory leak from InitialLogInVC

import UIKit

class IntialLoginInViewController: UIViewController {
@IBOutlet weak var backgroundAlbumArt: UIImageView!
@IBOutlet weak var foregroundAlbumArt: UIImageView!
@IBOutlet weak var musicNameLabel: UILabel!
private weak var imageOne = UIImage(named: "taste.jpg")
private weak var imageTwo = UIImage(named: "NavReckless.jpg")
private weak var imageThree = UIImage(named: "watch.jpg")
private weak var imageFour = UIImage(named: "juicewrld.jpg")

lazy var imageInformation = [(name:"Taste - Tyga", image:imageOne),(name:"Reckless - Nav", image: imageTwo),(name:"Watch - Travis Scott", image: imageThree), (name:"Goodbye & Good Riddance - Juice Wrld", image: imageFour)]
private var currentIndex = 0
static var spotifySession: AnyObject?

override func viewDidLoad() {
super.viewDidLoad()
foregroundAlbumArt.image = imageOne
backgroundAlbumArt.image = imageOne
musicNameLabel.text = imageInformation[0].name
let _ = Timer.scheduledTimer(timeInterval: 10.0, target: self, selector: #selector(imageRefresh), userInfo: nil, repeats: true)
}

override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}

@objc func imageRefresh(){
if currentIndex == imageInformation.count - 1 {
currentIndex = 0
}
else {
currentIndex += 1
}
//Update Label
UIView.transition(with: self.musicNameLabel, duration: 2.0, options: [.transitionCrossDissolve] , animations: {
self.musicNameLabel.text = self.imageInformation[self.currentIndex].name

}, completion: nil)
//Update foreground Album
UIView.transition(with: self.foregroundAlbumArt, duration: 2.0, options: [.transitionCrossDissolve] , animations: {
self.foregroundAlbumArt.image = self.imageInformation[self.currentIndex].image
}, completion: nil)
//Update background Album

UIView.transition(with: self.backgroundAlbumArt, duration: 2.0, options: [.transitionCrossDissolve] , animations: {
self.backgroundAlbumArt.image = self.imageInformation[self.currentIndex].image
}, completion: nil)

}

}

最佳答案

试试这个

    //Update Label
UIView.transition(with: self.musicNameLabel, duration: 2.0, options: [.transitionCrossDissolve] , animations: { [weak self] in
guard let `self` = self else { return }
self.musicNameLabel.text = self.imageInformation[self.currentIndex].name

}, completion: nil)

//Update foreground Album
UIView.transition(with: self.foregroundAlbumArt, duration: 2.0, options: [.transitionCrossDissolve] , animations: { [weak self] in
guard let `self` = self else { return }
self.foregroundAlbumArt.image = self.imageInformation[self.currentIndex].image
}, completion: nil)
//Update background Album

UIView.transition(with: self.backgroundAlbumArt, duration: 2.0, options: [.transitionCrossDissolve] , animations: { [weak self] in
guard let `self` = self else { return }
self.backgroundAlbumArt.image = self.imageInformation[self.currentIndex].image
}, completion: nil)

关于ios - Xcode 9 : Getting More Information On Memory Leak,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51995870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com