When I destroy my object in Swift, it does not free up RAM

This is a test, an action to create, and one to destroy an object, but when I destroy it, my RAM still uses the same amount of memory (about 30 MB).

var missileImage: UIImageView!
weak var img: UIImage!

@IBAction func createImg(sender: AnyObject) {
    missileImage = UIImageView(frame: CGRectMake(CGFloat(arc4random() % 100), 200, 50, 30))
    img = UIImage(named: "house.jpg")
    missileImage.image = img
    missileImage.tag = 10001
    self.view.addSubview(missileImage)
}

@IBAction func destroyImg(sender: AnyObject) {
    self.view.viewWithTag(10001)?.removeFromSuperview()
    img = nil
    missileImage = nil
}
+4
source share
1 answer

UIImage(named:)caches images. They will not be released until you receive a warning about saving memory. However, they will be automatically released at that time, even if your application is in the background (usually you do not get the opportunity to reduce memory if a warning appears when you are in the background). Cache usesNSPurgableData, . . , , , , ( ), iOS , , , , .

, , . , Apple , . , , , UIImage(contentsOfFile:). . , Apple , , .

+20

All Articles