Fix false-positive ArrayPtr dispose warning#370
Fix false-positive ArrayPtr dispose warning#370johnml1135 wants to merge 2 commits intosillsdev:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refines ArrayPtr’s finalizer-time debug warning so shutdown logs don’t report “Missing Dispose()” for wrapper instances that do not own unmanaged memory (e.g., ArrayPtr.Null), while keeping the warning for instances responsible for freeing unmanaged buffers.
Changes:
- Remove legacy commented-out “hack” related to excluding the null instance from finalizer behavior.
- Gate the “Missing Dispose()”
Debug.WriteLineIfwarning onm_ownMemoryto avoid warning for non-owning wrappers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/SIL.LCModel.Utils/ArrayPtr.cs
Outdated
| // If you're getting this line it means that you forgot to call Dispose(). | ||
| Debug.WriteLineIf(!disposing,// && this != s_Null, // TODO (Hasso) 2016.11: is this the only place this ugly hack is needed? | ||
| // Only warn for finalized instances that actually own allocated memory. | ||
| Debug.WriteLineIf(!disposing && m_ownMemory, |
There was a problem hiding this comment.
The new warning condition uses m_ownMemory, but m_ownMemory == true does not necessarily mean unmanaged memory was actually allocated (e.g., new ArrayPtr() sets m_ownMemory = true while m_ptr is still IntPtr.Zero until Resize is called). As written, finalized instances created via the default ctor but never allocated could still emit the warning, which contradicts the new comment and can still produce false positives. Consider including an allocation check (e.g., m_ptr != IntPtr.Zero / m_Size >= 0) or adjust the comment to match the actual condition.
| Debug.WriteLineIf(!disposing && m_ownMemory, | |
| Debug.WriteLineIf(!disposing && m_ownMemory && m_ptr != IntPtr.Zero, |
jasonleenaylor
left a comment
There was a problem hiding this comment.
@jasonleenaylor reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on johnml1135).
Summary
Suppress the ArrayPtr finalizer warning for non-owning wrappers such as ArrayPtr.Null while preserving the warning for managed-owned unmanaged buffers.
Why
FieldWorks debug sessions were reporting a misleading "Missing Dispose() call for ArrayPtr" message at shutdown even when the finalized ArrayPtr instance did not own unmanaged memory.
Validation
This change is