0

I'm setting a bottom buttons StackView and I just found out that whenever I set it I find you that the memory use goes up immediately.

this is the code I implement in viewDidLoad() to setUp the bottom stackView:

 @objc fileprivate func setUPUI(){
    
    let buttonsStackView = UIStackView(arrangedSubviews: [acceptButton, detailButton, cancelButton])
    
    
    buttonsStackView.axis = .horizontal
    buttonsStackView.distribution = .equalSpacing
    buttonsStackView.alignment = .center
    
    buttonsStackView.spacing = 20
    
    //defining buttons Constraints
    acceptButton.heightAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
    acceptButton.widthAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
    
    detailButton.heightAnchor.constraint(equalToConstant: centerViewSize).isActive = true
    detailButton.widthAnchor.constraint(equalToConstant: centerViewSize).isActive = true
    
    cancelButton.heightAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
    cancelButton.widthAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
    
    
    
    //setting shadows
    acceptButton.setupShadow(opacity: 0.7, radius: 4, offset: .init(width: 0, height: 0), color: .darkGray)
    detailButton.setupShadow(opacity: 0.7, radius: 4, offset: .init(width: 0, height: 0), color: .darkGray)
    cancelButton.setupShadow(opacity: 0.7, radius: 4, offset: .init(width: 0, height: 0), color: .darkGray)
    
    
    buttonsStackView.translatesAutoresizingMaskIntoConstraints = false
    
    
    self.view.addSubview(buttonsStackView)
    
    buttonsStackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -5).isActive = true
    buttonsStackView.heightAnchor.constraint(equalToConstant: 90).isActive = true
    buttonsStackView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    buttonsStackView.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor,constant: 20).isActive = true
    buttonsStackView.trailingAnchor.constraint(lessThanOrEqualTo: view.trailingAnchor,constant: -20).isActive = true
   }

When I load the viewController it passes from 41MB to 296MB

memory use

Instrument report

allocation report

leaks report

StackGU
  • 868
  • 9
  • 22
  • 1
    “the memory use goes up immediately” Evidence? Evidence that the memory rise is also a leak? (Those are two very different things.) – matt Sep 08 '20 at 14:00
  • @matt thanks for the clarification, it passes from 41MB of memory use to 296MB so I guess it's a leak – StackGU Sep 08 '20 at 14:06
  • A leak is not something you guess about. This can be high memory usage without being a leak. To find out what's going on, use Instruments. Your code alone is not enough to explain the memory usage; perhaps you are displaying large images or similar. Only you know, so only you can work out what's happening. Instruments will tell you very clearly. You say "When I load the viewController" so it could be anything about the view controller that's causing the memory usage. I do not for a moment believe that it is the stack view. – matt Sep 08 '20 at 14:22
  • @matt thanks, I did as you suggested and I uploaded the instrument report, could you tell what is the problem from that report? – StackGU Sep 08 '20 at 15:02
  • No, that looks like a time profile. You want a Leaks and Allocations report. – matt Sep 08 '20 at 15:15
  • I uploaded both of them right now @matt – StackGU Sep 08 '20 at 15:33
  • Seems like a duplicate of https://stackoverflow.com/questions/54022559/iosurface-gradually-increases-memory-in-ios-12-and-above. As I said before, it seems you are loading a huge image. – matt Sep 08 '20 at 15:47

0 Answers0