-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Release the resources #3868
Release the resources #3868
Conversation
There was a problem hiding this 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 optimizes resource management by releasing unmanaged resources more proactively while extending IDisposable implementations and tests. Key changes include:
- Adding a unit test to verify cache capacity handling in HeaderCache.
- Extending TrackerBase to implement IDisposable.
- Disposing resources in StateStore and NeoStore to prevent resource leaks.
- Enforcing a cache limit in HeaderCache.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs | Adds a new test (TestHeaderCache_Limit) to validate the cache capacity logic. |
src/Plugins/TokensTracker/Trackers/TrackerBase.cs | Extends TrackerBase class to implement IDisposable for safer resource management. |
src/Plugins/StateService/Storage/StateStore.cs | Disposes the state snapshot and resources in both UpdateLocalStateRoot and PostStop. |
src/Plugins/ApplicationLogs/Store/NeoStore.cs | Adds disposal of _blocklogsnapshot to ensure resource release. |
src/Neo/Ledger/HeaderCache.cs | Enforces a limit on headers to prevent over-allocation and potential memory issues. |
Comments suppressed due to low confidence (1)
src/Neo/Ledger/HeaderCache.cs:110
- [nitpick] Consider adding curly braces '{}' around the if-statement body to improve clarity and reduce the risk of errors in future modifications.
if (headers.Count >= 10000)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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 addresses memory issues by optimizing resource management and enforcing limits in cache implementations. Key changes include the addition of new unit tests for header cache limits, the introduction of nullable reference handling and Dispose pattern in TrackerBase, and various adjustments to resource management in StateStore, NeoStore, and HeaderCache.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs | Adds a test method to ensure the HeaderCache respects its capacity limit. |
src/Plugins/TokensTracker/Trackers/TrackerBase.cs | Enables nullable reference handling and implements the Dispose pattern for improved resource management. |
src/Plugins/StateService/Storage/StateStore.cs | Refactors singleton handling and snapshot disposal; however, an issue was introduced with cache initialization. |
src/Plugins/ApplicationLogs/Store/NeoStore.cs | Disposes of the block log snapshot to release resources. |
src/Neo/Ledger/HeaderCache.cs | Introduces a constant for maximum headers and updates the Add method to enforce the cache limit. |
src/Neo/Ledger/Blockchain.cs | Updates header addition logic to check for cache capacity before adding headers. |
Comments suppressed due to low confidence (1)
src/Plugins/TokensTracker/Trackers/TrackerBase.cs:98
- Using the null-forgiving operator on '_levelDbSnapshot' may lead to a NullReferenceException if it is null. Consider adding an explicit null-check to guarantee that _levelDbSnapshot is not null before calling Put.
_levelDbSnapshot!.Put(Key(prefix, key), value.ToArray());
* master: (163 commits) [style] Added some var styles (neo-project#3867) [`fix`] stop syncing on block 1465790 (neo-project#3888) Optimize block deserialization (neo-project#3879) Avoid double `ToArray` on `OnInvMessageReceived` (neo-project#3875) style: format long lines (neo-project#3884) optimize: return GetFileNameWithoutExtension(Path) if name is not set (neo-project#3883) Fix possible null exception (neo-project#3880) Remove linkedList (neo-project#3873) Optimize Uint160 and Uint256 constructor (neo-project#3872) Release the resources (neo-project#3868) [Clean] Remove `IRawReadOnlyStore` (neo-project#3869) move non-plugins out of plugins (neo-project#3863) feature: set name when create wallet (neo-project#3866) Native: swap Policy's `[get/set]AttributeFee` implementations (neo-project#3859) Fix: concurrent conflict in Cache.CopyTo (neo-project#3860) Fix: add default key parameter in help cmd (neo-project#3865) [Plugin UT] add more rpcserver UTs (neo-project#3864) config: upgrade NeoFS chains protocol configuration (neo-project#3858) [`Optimization`]: add exception message to `ArgumentException` (neo-project#3862) Native: unify arguments naming of CryptoLib's `verifyWith*` methods (neo-project#3855) ... # Conflicts: # benchmarks/Neo.VM.Benchmarks/OpCode/Arrays/OpCode.ReverseN.cs # benchmarks/Neo.VM.Benchmarks/Program.cs # src/Neo/Neo.csproj # src/Neo/ProtocolSettings.cs # src/Neo/SmartContract/ApplicationEngine.cs # src/Neo/SmartContract/Native/NeoToken.cs # src/Neo/SmartContract/Native/RoleManagement.cs # tests/Neo.UnitTests/SmartContract/Manifest/UT_ContractManifest.cs # tests/Neo.UnitTests/SmartContract/Manifest/UT_ContractPermission.cs # tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs # tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs # tests/Neo.UnitTests/UT_ProtocolSettings.cs # tests/Neo.VM.Tests/UT_ReferenceCounter.cs
Description
This pr tries to hunt for the frequent memory issues reported by community.
Fixes #
Type of change
How Has This Been Tested?
Checklist: