| With the rapid development of artificial intelligence and machine learning,the use of Python has gradually expanded.Python has gradually surpassed static programming languages such as Java and C/C++as the most widely used language.Although Python has a memory management mechanism,it also has the problem of memory leaks.Memory leaks are not easily detected.With the running of the program,the performance of the program is continuously reduced,and in severe cases,the entire system will be destroyed,so it is very important to detect memory leaks in Python programs.At present,the research on static memory leak detection methods for static programming languages such as Java and C/C++ has been relatively mature.However,in dynamic programming languages such as Python,object types are dynamically variable during program execution,which makes it difficult to perform static analysis.Therefore,the focus of memory leak research at this stage is mostly the judgment and recovery after the defect occurs,and the research on static detection is still in its infancy.In response to the above problems,this paper proposes a static detection method for Python memory leak defects.The specific research contents are as follows:(1)Study the Python memory leak defect modeBy studying the Python memory management mechanism and dynamic language features,analyzing a large number of Python program memory leak source codes,and summarizing the code characteristics of Python memory leak defect patterns,the state transition diagram is used to abstractly describe the memory leak defect patterns.(2)Propose a pattern matching algorithm for memory leak defects,Designed a method to improve detection accuracyAiming at the characteristics of Python memory leaks,a pattern matching algorithm for memory leak defects is proposed,and in the process of analyzing the nodes of functions,type deduction technology is used to extract the definition and usage information of objects.Combining type inference with on-demand variable object flowsensitive alias analysis method and dynamic language data dependency analysis method to construct object information quintuple to improve the accuracy of analysis.(3)Design a detection system for memory leak defectsBased on the Python memory leak defect model,a memory leak defect detection system is designed.The core modules include a preprocessing module,a precision improvement module and a memory leak defect detection module.The system can realize the memory leak detection of Python programs.Based on the Python memory leak defect detection method proposed in this paper,the detection system is implemented,and the experimental verification is carried out in 8 open source projects.The experimental results show that the correct rate of defect reporting is 76.85%before adding the precision improvement module,and the detection system can detect memory leak defects in the code to a certain extent.The results of comparative experiments prove that the method in this paper improves the accuracy rate to 87.27%through data dependency analysis of dynamic language and flow-sensitive alias analysis of variable objects as needed,which shows the superiority of this method. |