天天看点

EhLib的内存泄漏

EhLibADO,

initialization

  RegisterDatasetFeaturesEh(TADOSQLDatasetFeaturesEh, TADOQuery);

  RegisterDatasetFeaturesEh(TADOCommandTextDatasetFeaturesEh, TCustomADODataSet);

EhLibCDS

{$IFDEF EH_LIB_6}

  RegisterDatasetFeaturesEh(TCDSDatasetFeaturesEh, TCustomClientDataSet);

{$ELSE}

  RegisterDatasetFeaturesEh(TCDSDatasetFeaturesEh, TClientDataSet);

{$ENDIF}

居然没有UnRegisterData……看来EhLib团队也有菜鸟

移植到DLL中,退出EXE报AV错误,原因是这里没有UnRegister

修改后用FastMM4发现有内存泄漏

查看RegisterDatasetFeaturesEh发现

procedure RegisterDatasetFeaturesEh(DatasetFeaturesClass: TDatasetFeaturesEhClass;

  DataSetClass: TDataSetClass);

var

  DatasetFeatures: TDatasetFeaturesEh;

  ClassIndex: Integer;

begin

  DatasetFeatures := DatasetFeaturesClass.Create;

  DatasetFeatures.FDataSetClass := DataSetClass;

  if DatasetFeatures.FDataSetClass = nil then

    Exit;   //既然等Nil,何必要去创建(DatasetFeatures)……

  ClassIndex := DatasetFeaturesList.IndexOf(DatasetFeatures.FDataSetClass.ClassName);

  if ClassIndex >= 0

    then DatasetFeaturesList.Objects[ClassIndex] := DatasetFeatures    //如果已经有了之前那个对象怎么办……

    else DatasetFeaturesList.AddObject(DatasetFeatures.FDataSetClass.ClassName,

            DatasetFeatures);

end;

//还好提供源码。修正后,没有问题了