delphi - Freeing Multiply-referenced Objects -


This is another post about which I got an intraab application, according to the report of FastMM4, memory leaks had a 2 MB text file, where I found it below in 115 instances of leaking 52 bits of each class is.

Leaks are from the mere complex implication and class handling. If the app needs every moment of the classroom to work now, then I'm looking for some way to either clone the clone with some straightforward cleaning, or referencing it in a different way, or doing ..?

The first instance of the class (TCwcBasicAdapter) has been added to a local variable A TOBjectList (not the owner) that is deleted and deleted with TObjectList (FCDSAdapters):

  Process TCwcDeclaration.AttachAdapter (DS: TDataSource; Constants Run, KeyFN, TitleFN: String; Constant Multiple: Boolean = Fault; Concept Allow Attachment: Boolean = Falls, Const. Vacation: Boolean = Falls); Var form: TCVC session form; Adapter: TCwcCDSAdapter; Mainfield, TitleField: TFild; Start the form: = GetForms (FormName); Keiffield: = DS. Dataset.Findfield (KFN); TitleField: = DS.DataSet.FindField (TitleFN); Adapter: = TCVicBasic adapters.creative (DS, keyfield, titlefield, multiple); Adapter.AttachDBPersist (Self.DBPersist); Forms.AttachDataAdapter (adapter); Forms.SetAllowAttachments (AllowAttachment); Forms.SetAllowComments (AllowComment); End; Process TCwcSessionForms.AttachDataAdapter (aCDSAdapter: TCwcCDSAdapter); Var index: integer; If (FCDSAdapters.IndexOf (aCDSAdapter) -1) Exception.CreateFmt raise (try to be attached% 0 on the duplicate adapter: s', [FFormClassName]); Index: = FCDAdapters. Add (ACDSAdapter); If (FDefaultAdapterIndex = -1) then FDefaultAdapterIndex: = Index; End; Second acceleration of the class is also in the form of a local variable which is not included in the tobogguit list (does not occur) and is destroyed with the tubabilist (adapter): < / P> 
  process TCwcCDSMulticastList.InitializeAdapters (a session form: TCwcSessionForms); Var i, Calculation: Integer; Adapter: TCwcCDSAdapter; Tampmultichast: TCVCCCSECCMultichast; Starting Count: = A SessionForm. GateDataAdapterCount; To: = 0 start the adapter (c): = aSessionForms.GetDataAdapter (i); TempMulticast: = FindDataSource (Adapter.DataSource); If (TempMulticast = Void) then start TempMulticast: = TCwcCDSEventMulticast.Create (Adapter.DataSource); Try FMulticastList.Add (TempMulticast); Excluding Free and Neil (Tampamulticast); Increased; End; End; TempMulticast.AddObserver (adapter); FAdapters.Add (adapter); End; End;  

Class III rebound, Tamp Melticast. A supervisor from above the Ad Observer (adapter) line is in the form of a pattern. Supervisor TObjectList FObservers (owner) is added:

  Process TCwcCDSEventMulticast.AddObserver (constant aCDSAdapter: TCwcCDSAdapter); Start FObservers.Add (TCwcCDSAdapterObserver.Create (aCDSAdapter)); End; Constructor TCWCDADADOO OpAbSverver Composition (Concept ACDSA Adapter: TCWCCDADEptitor); Start the heritage; Create; FOnStateChange: = aCDSAdapter.OnStateChangeIntercept; FOnAfterDelete: = aCDSAdapter.AfterDeleteIntercept; FInvalidateCursors: = aCDSAdapter.InvalidateCursors; End;  

TCwcBasicAdapter is leaking here, not clean when FObservers is destroyed.

The latest thing I have tried is changing the FObservers to the owner, to make a private area adapter, freeing the private sector in TCwcCDSAdapterObserver.Destroy, but that causes errors.

Thanks,

Paul Rice

if the lists If they are not the owner, they will not empty the object when the list is released. Just call Remove on each item or it will not do this either. You have to iterate through the list and make a free call to each item in the list, and then the list will automatically be set free.

If you make the owners of the lists, When you will empty the list.

  i: = = 0 for FAdapters [I]); FreeAndNil (FAdapters);  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -