Post

Replies

Boosts

Views

Activity

Reply to Identifying memory leaks
@eoonline - thank you for the tips on the memory graph. I have followed your recommendation and can now see just the object I am creating. I have turned on “Malloc Stack Logging”. Looking at the size of each object the largest is 272 bytes. Clicking on the small arrow at the top takes me to the relevant code. But this doesn't illuminate the issue. One observation I have had is the memory usage increases only when my app is playing an avplayer. Upon pausing it the memory does not increase. Here is the code for my avplayer in case that helps. @Binding var currentPlayerTime: CMTime var playerView: AVPlayerView var player: AVPlayer func makeNSView(context: Context) -> AVPlayerView { playerView.player = player playerView.controlsStyle = .none playerView.player?.isMuted = true playerView.delegate = context.coordinator return playerView } func updateNSView(_ nsView: NSViewType, context: Context) { } func makeCoordinator() -> Coordinator { return Coordinator(self) } class Coordinator: NSObject, AVPlayerViewDelegate { var parent: VideoPlayerViewRepresentable private var timeObserverToken: Any? init(_ parent: VideoPlayerViewRepresentable) { self.parent = parent super.init() // Add time observer let interval = CMTime(value: 1, timescale: 24) timeObserverToken = parent.player.addPeriodicTimeObserver(forInterval: interval, queue: .main) { [weak self] time in self?.parent.currentPlayerTime = time } } deinit { // Remove time observer when Coordinator is deallocated if let timeObserverToken = timeObserverToken { parent.player.removeTimeObserver(timeObserverToken) } } } }
5d
Reply to Identifying memory leaks
@DTS Engineer - thank you for the reference document that helped a lot. I'm now looking at allocations. In 12 minutes my app went from using 52MB to over 200MB. I looked through all mallocs and ordered the list of responsible callers but saw nothing on all of them that looked familiar (e.g. code from my app). Most of them looked like the following - which had around 60,000 allocations (Malloc 352 had over 100,000 allocations with the same caller). How can I narrow this down?
5d
Reply to Hangs with non-busy main thread using Instruments
Did you ever resolve this? I have a similar issue where my app has an intermittently 'frozen' UI on start but when I investigate I see a similar situation to you. The issue is it doesn't show where in the code is causing the issue. Frustratingly, I see a blocked main thread in instruments whether the UI is blocked or not! I'm curious if you see something similar.
Jun ’24