Skip to content
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

feat: fix memory leak in Enforce() #246

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Conversation

ailiujiarui
Copy link
Contributor

@ailiujiarui ailiujiarui commented Apr 15, 2024

Fix: #243

Description

When the enforce function is called 10,000 times, the memory stays at 3MB for a while before it linearly increases to around 40MB. Using the performance analysis tool built into VS2022, snapshots were taken during the program’s runtime to compare the differences in memory and call counts. Clicking on the snapshot allows you to see which functions were called in the stack and what objects exist.
After repeated comparisons, it was found that after the number of calls to GetExprtkFunction increased, many smart pointer objects were created and not released in time, causing the memory to continue to rise. I modified the function’s running logic, using an object pool to store the required objects and returning objects as needed. After completion, the memory occupied by the same number of calls dropped to 4~5MB.

Screenshots/Testimonials

before:
image

now:
image

@casbin-bot
Copy link
Member

@EmperorYP7 @sheny1xuan @cs1137195420 please review

@hsluoyz
Copy link
Member

hsluoyz commented Apr 18, 2024

Hi @fishsclue, can you test this PR?

@hsluoyz hsluoyz changed the title fix: fix the bug that memory leak detection feat: fix memory leak in Enforce() Apr 19, 2024
@hsluoyz hsluoyz merged commit 5f01444 into casbin:master Apr 19, 2024
25 of 26 checks passed
Copy link

🎉 This PR is included in version 1.57.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory Leak Detection: Casbin
3 participants