Skip to content

Conversation

@averyhome
Copy link

Summary

This PR fixes two memory leak issues:

  1. NWPathMonitor was not properly cancelled, causing retain cycles and memory leaks.
  2. requestController retained cycles

Changes

  • Add monitor.cancel() in appropriate deinit or shutdown logic.
  • Fix retain cycle by using [weak self] in closures.
  • Add relevant cleanup code to avoid strong references.

Motivation

These issues caused retained cycles in production use, especially with reconnect behavior and long-running sessions.

Memory leak caused by requestController cycle
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @averyhome

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

home-assistant bot commented Jun 3, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@bgoncal
Copy link
Member

bgoncal commented Jul 3, 2025

Is this PR ready or you plan to add anything else?

@bgoncal bgoncal requested a review from Copilot September 17, 2025 12:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes memory leaks by addressing retain cycles in the network monitoring subsystem and connection management.

  • Adds proper cleanup for NWPathMonitor to prevent retain cycles
  • Converts strong capture to weak capture in request controller closures

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Source/Internal/HAReconnectManager.swift Adds deinit method to cancel pathMonitor and prevent memory leaks
Source/Internal/HAConnectionImpl.swift Changes strong capture to weak capture for requestController to break retain cycle

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants