Fix memory leak and add Cython 3.0 support - #8
Open
niko-zvt wants to merge 1 commit into
Open
Conversation
- Migrate to Cython 3.0.11 and modern cythonize() API - Add pyproject.toml to fix build isolation issues - Implement proper __dealloc__() methods to prevent memory leaks - Remove deprecated Cython.Distutils and -Wstrict-prototypes workaround - Update to Python 3 syntax (print statements) - Add macOS troubleshooting for rpath issues - Bump version to 0.0.2
Author
|
@poine @schmittlema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two critical issues in pysbpl:
Both fixes must be applied together because the memory leak fix adds C++ operators that require the Cython 3.0 migration to compile correctly.
Problem 1: Memory Leak
Issue
Each pathfinding operation leaks ~300-500 MB of virtual memory because C++ objects are created with
newbut never freed. Over thousands of operations, this accumulates 10-25 GB and eventually crashes withMemoryError.Root Cause
Missing
__dealloc__()methods in Cython wrapper classes:EnvironmentNAVXYTHETALAT: Leaks C++ environment object (~300 MB) and malloc'd mapdataARAPlanner: Leaks C++ planner object (~200 MB)Solution
Added proper
__dealloc__()destructors following Cython documentation.Problem 2: Cython 3.0 Incompatibility
Issue
The
setup.pyuses deprecatedCython.Distutils.build_extAPI from Cython 0.x, which fails to process the# distutils: language = C++directive correctly. This causes compilation errors:Root Cause
Cython.Distutilsis deprecated since Cython 3.0. The C++ language directive is ignored, causing compilation in C mode. C++ operators (new,del) are only available in C++ mode.Solution
Migrated to modern
Cython.Build.cythonize()API:Backward Compatibility
100% backward compatible for users:
Build requirement:
Cython == 3.0.11for compilationList of changes: