@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)
}
}
}
}