Skip to content

fix: remove stale watchers when overwriting references - #1216

Open
YashAnand69 wants to merge 2 commits into
holoviz:mainfrom
YashAnand69:fix/963-clear-overwritten-reference-watchers
Open

YashAnand69 wants to merge 2 commits into
holoviz:mainfrom
YashAnand69:fix/963-clear-overwritten-reference-watchers

Conversation

@YashAnand69

@YashAnand69 YashAnand69 commented Oct 4, 2026 •

Copy link
Copy Markdown

Description

Overwriting a parameter reference with a plain value removes its reference entry but leaves the source watcher attached. A detached view remains alive while another view uses the same source, and a detached source can also remain alive unnecessarily.

Route removal through the existing reference-registration cleanup so obsolete watchers are removed and watchers for the remaining references are rebuilt. Async cancellation continues through that same path. Three regression cases cover collection of the detached target and source, and synchronization of a remaining nested reference.

Refs #963. This addresses overwritten references; it does not change ownership or retention of references that remain active.

Reproduction:

import gc
import weakref
import param

class View(param.Parameterized):
    value = param.Number(default=0, allow_refs=True)

source = View()
detached = View(value=source.param.value)
active = View(value=source.param.value)
ref = weakref.ref(detached)
detached.value = 0
del detached
gc.collect()
print(ref() is None)  # Before: False. After: True.
source.value = 2
print(active.value)   # 2 in both cases.

On main, the two collection regressions fail and the remaining-reference case passes. With the fix, pytest tests/testrefs.py -q reports 91 passed and 1 skipped. pytest tests -q reports 1,977 passed, 40 skipped, 2 xfailed and 8 subtests passed on Python 3.12.14. Changed-file pre-commit checks pass, including Ruff and typos. Documentation notebook tests were not run.

These screenshots show live diagnostic output from the reproduction above, rendered with Panel; this is a nonvisual memory-management fix.

Before After
Detached view is retained Detached view is collected

Related documentation: Parameter references, developer guide.

AI Disclosure

Tool & Model: Codex with GPT-6.
Usage: assisted with tracing watcher retention, implementation, regression tests, running checks, reviewing the diff and preparing this description. The reproduction was run against main and the fix; the test results and limitations above are from actual executions.

  • I have tested all AI-generated content in my PR.
  • I take responsibility for all AI-generated content in my PR.

Checklist

  • Tests added and are passing
  • Added documentation (no public API or usage change)

October 31 follow-through: merged latest main af94e0c via 6bd0d7d, resolving the test import conflict while preserving current upstream reactive changes. The two collection regressions still fail on exact latest-main production source; the shared nested-reference control passes. The counts above are from the updated branch. Pinned pre-commit checks pass; upstream tests/zizmor workflows await maintainer approval. AI-assisted resolution and independent final-diff review.

Resolve test import overlap while retaining upstream reactive changes.

Assisted-by: Codex:GPT-6
@YashAnand69

Copy link
Copy Markdown
Author

Merged current main (af94e0c) in 6bd0d7d and resolved the test-import conflict, preserving the newer reactive implementation. Re-ran the three original regressions against exact current-main production source: both collection cases still fail, while the surviving nested-reference control passes. With this patch, reference tests pass (91 passed, 1 skipped); the full tests directory reports 1,977 passed, 40 skipped, 2 xfailed and 8 subtests passed. Pinned pre-commit checks pass. The production fix and its scope are unchanged; documentation notebooks were not run. AI-assisted conflict resolution and independent diff review.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant