国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

定義公共模型,使用static。是否有內(nèi)存泄漏問題(webman)

hunma

問題描述

定義一個公共的模型繼承類,看了文檔說使用過多static會造成內(nèi)存泄漏。這樣寫會遇到內(nèi)存泄漏或者是其他的問題嗎

代碼

公共代碼
<?php

namespace ceshi\basic;

use think\db\Query;
use think\Model;
use think\model\concern\SoftDelete;

/**
 * 基礎(chǔ)模型類
 * 提供通用的數(shù)據(jù)庫操作方法
 */
class BaseModel extends Model
{
    // 使用軟刪除功能
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     * 統(tǒng)一ID數(shù)據(jù)更新
     * @param array $data 更新數(shù)據(jù),必須包含 id
     * @return bool
     * @throws \Exception
     */
    public static function edit(array $data): bool
    {
        self::validateId($data);

        $model = self::findOrFail($data['id']);
        return $model->save($data);
    }

    /**
     * 獲取分頁列表
     * @param array $where 查詢條件
     * @param array $order 排序規(guī)則
     * @param string $field 查詢字段
     * @param int $page 當前頁碼
     * @param int $limit 每頁條數(shù)
     * @param string $group 分組字段
     * @return array
     */
    public static function getList(array $where = [], array $order = ['id' => 'DESC'], string $field = '*', int $page = 1, int $limit = 10, string $group = ''): array
    {
        $query = self::buildQuery($where, $order, $field, $group);
        return $query->page($page, $limit)->select()->toArray();
    }
}
繼承公共
<?php
namespace app\model\sys;

use ceshi\basic\BaseModel;

class SysUserModel extends BaseModel{

    protected $table = 'sys_user';
}
調(diào)用
<?php
namespace app\test\controller;

use app\model\sys\SysUserModel;
use hunma\basic\ApiResponse;
use hunma\basic\BaseController;

class TestBaseModelController extends BaseController
{
    public function success(){
        $data = SysUserModel::find(1);
        return ApiResponse::success($data);
    }
}
525 2 0
2個回答

jolalau

文檔里明確表示“static關(guān)鍵字的數(shù)組”,static數(shù)組使用不當,會導致數(shù)據(jù)無限膨脹然后引起內(nèi)存泄露,這是寫代碼人的問題!和靜態(tài)方法那是兩碼事!

walkor 打賞

文檔沒有說過 使用過多static會造成內(nèi)存泄漏,只是提示使用static數(shù)組時注意不要無限添加數(shù)據(jù)。
業(yè)務(wù)發(fā)生內(nèi)存泄露幾率很低,基本不用考慮。即使發(fā)生webman也會再適當?shù)臅r候自動平滑重啟對應(yīng)進程,不影響業(yè)務(wù)。

??