Abstract:Resource leaks are software defects caused by improper closing of limited system resources, and they are prevalent in program software written in various languages and somewhat concealed. Traditional defect detection approaches rely on rules and heuristics. In recent years, deep learning approaches have used various code representations and technologies, such as RNN and GNN, to understand code semantics. Language models (LMs) have demonstrated significant advancements in code understanding and generation in recent research, yet their effectiveness in resource leak detection remains underexplored. This study evaluates traditional model-based, small language model-based (SLM-based) and large language model-based (LLM-based) methods for resource leak detection and investigates enhancements through few-shot learning, fine-tuning, and integration of static analysis with LLMs. Using the JLeaks and DroidLeaks datasets, we evaluate model performance from multiple perspectives, including the root causes of leaks, resource types, and code complexity. Our findings indicate that fine-tuning can significantly improve LM’s performance. However, most models need further improvement in detecting resource leaks from third-party libraries. Furthermore, code complexity has a greater impact on traditional model-based detection methods for resource leak detection.