Repository navigation
Conversation
…t are not owned by the directory
vepadulano
left a comment
There was a problem hiding this comment.
Thank you! In principle LGTM, but see some comments for the tests
Co-authored-by: Vincenzo Eduardo Padulano <v.e.padulano@gmail.com>
Test Results 24 files 24 suites 3d 23h 48m 20s ⏱️ For more details on these failures, see this check. Results for commit 2b10086. ♻️ This comment has been updated with latest results. |
vepadulano
left a comment
There was a problem hiding this comment.
Code changes LGTM. I will wait also for others to approve. Meanwhile, I have another suggestion to make the test future-proof.
…y in the test Assisted-by: claude-code:claude-opus-5-5
| registered = bool(f.GetList().FindObject(name)) | ||
| self.assertEqual(obj.__python_owns__, not registered, msg=name) | ||
| # The object is still alive | ||
| self.assertEqual(f.Get(name).GetName(), name) |
There was a problem hiding this comment.
This has changed meaning now: obj is kept in the scope of the loop, so this check will always be True. Before, you were checking that after deleting obj the file was still holding it alive, which depends on whether it's registered with the file or not.
This Pull request:
Changes or fixes:
TDirectoryFile.Getin Python reads the object withGetObjectChecked()and binds the returned pointer without taking ownership. Objects that are not added to the directory's list are therefore never deleted. This covers non-TObjects likestd::vectororROOT::RNTuple, and TObjects withoutDirectoryAutoAdd, likeTGraphorTObjString. CallingGetagain creates a new copy each time, so memory grows. For example, reading the RNTuple anchor of a file:Python now takes ownership of the returned object, except when the directory holds it in its list. That is the case for histograms, trees and subdirectories, which keep being owned by the directory as before. The fallback for when no key is found is not changed, because it returns objects that are already in memory and owned by someone else. Checking the directory's list (a
THashList) adds about 4 µs to eachGetcall, and this does not depend on the number of objects in the directory.I added a test to
tdirectory_tfile.pythat checks that aTGraph, aTObjStringand astd::vectorread withGetare owned by Python, and that aTH1F, aTTreeand a subdirectory are not and are still usable from the directory after the Python object is deleted. The test fails without the fix.Checklist:
I also checked that calling
Getmany times no longer makes memory grow forTGraph,TObjString,std::vectorandRNTuple, and thattdirectory_tfile.pypasses under ASan with no double deletes.This PR fixes #16178