top-think / top-think/think-orm

4.0.7 常驻内存框架下出现内存泄漏问题

Open
#697 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

系统 windows 10
框架 Webman-framework v1.6.14
orm 4.0.7

orm从4.0.3升级到0.7版本后出现此问题

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in E:\www\webman\vendor\topthink\think-orm\src\Model.php on line 226
Worker process terminated with ERROR: E_ERROR "Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in E:\www\webman\vendor\topthink\think-orm\src\Model.php on line 226"

Model.php

    private static ?WeakMap $weakMap = null;
    private function setWeakData(string $key, string $name, $value): void
    {
        self::$weakMap[$this][$key][$name] = $value;
    }

webman里长生命周期的数组包括:

  1. static关键字的数组
  2. 单例的数组属性
  3. global关键字的数组

内存泄露问题是 在长生命周期里 无限膨胀的static数组导致

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with vendor/topthink/think-orm/src/Model.php around line 226 and inspect setWeakData and its static WeakMap usage. Compare the behavior between ORM 4.0.3 and 4.0.7 in a long-lived Webman worker on Windows 10. Done means the worker no longer shows unbounded memory growth or terminates with the reported memory-exhaustion error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.