Skip to content

Finalizer tries to dispose objects, that belong to previous Runtime "generation" #1073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lostmsu opened this issue Mar 3, 2020 · 2 comments
Assignees

Comments

@lostmsu
Copy link
Member

lostmsu commented Mar 3, 2020

Environment

  • Pythonnet version: master
  • Python version: any
  • Operating System: any

Details

  1. Initialize Runtime
  2. Create a few PyObjects, keep them somewhere
  3. Shutdown Runtime
  4. Initialize Runtime the second time
  5. Clear all alive reference to objects from step 2.
  6. Call GC.Collect and WaitForPendingFinalizers

Expected: XDecref should never be called on the handles in PyObjects from step 2.
Actual: XDecref is called on the handles in PyObjects from step 2.

I saw this happen even to .NET types reflected to Python like System.MulticastDelegate. Will soon open a PR with repro.

@lostmsu lostmsu self-assigned this Mar 26, 2020
@lostmsu
Copy link
Member Author

lostmsu commented Feb 21, 2021

Disposing objects from previous Python engine run does not seem to be a problem. There might have been an issue with that elsewhere, but it is not directly related.

@lostmsu lostmsu closed this as completed Feb 21, 2021
@lostmsu lostmsu reopened this Nov 9, 2021
@lostmsu
Copy link
Member Author

lostmsu commented Nov 9, 2021

The issue is back. See #1074 (comment)

Python 3.10 AMD64 debug build on Windows:

Runtime.Py_Initialize();
BorrowedReference builtins = Runtime.PyEval_GetBuiltins();
BorrowedReference iter = Runtime.PyDict_GetItemString(builtins, "iter");
var ownedIter = new NewReference(iter); // this basically does IncRef
Runtime.Py_Finalize();

Runtime.Py_Initialize();
ownedIter.Dispose(); // this basically does DecRef
Runtime.Py_Finalize(); // <- this blows up in PyGC_Collect -> validate_list

@lostmsu lostmsu closed this as completed Nov 23, 2021
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

No branches or pull requests

1 participant