The MASM Forum

Projects => ObjAsm => Topic started by: HSE on July 27, 2017, 04:23:28 AM

Title: Collection.inc
Post by: HSE on July 27, 2017, 04:23:28 AM
Hi Biterider!!

Using SortedCollection for items that belong to others data structures have the problem that leak memory (Done call DisposeAll, but items are disposed by the others structures).

I'am making a Done method in the descendent:
Method CompositionsCollection.Done, uses esi
SetObject esi
  .if [esi].pItems != NULL
MemFree [esi].pItems
.endif
MethodEnd


No problem. But I think could be interesting to add to collection a new method:Method Collection.Free, uses esi
SetObject esi
  .if [esi].pItems != NULL
  MemFree [esi].pItems
.endif
MethodEnd


Regards. HSE
Title: Re: Collection.inc
Post by: Biterider on July 27, 2017, 07:45:07 PM
Hi HSE
The basic functionality of SortedCollection is inherited from Collection. This object assumes that it handels other objects (called Items) and that their lifespan are controlled by the collection. In this case, the Done method calls DisposeAll that calls at the end DestroyItem. In the case, that you will not handle the Items in this way, you thve to redefine this method. That is all. Now it is your responsability to free them.
An example is the SortedDataCollection. Here the Items are memory chunks that are merely disposed with MemFree.

Method SortedDataCollection.DestroyItem, NOFRAME, pItem:POINTER
    .if POINTER ptr [esp + 8] != NULL     ;pItem
      MemFree POINTER ptr [esp + 8]       ;Remove the data from Heap
    .endif
MethodEnd


I hope this helps a bit  :biggrin:

Biterider
Title: Re: Collection.inc
Post by: HSE on July 28, 2017, 01:21:25 AM
Perfect! Thanks.

Quote from: Biterider on July 27, 2017, 07:45:07 PM
This object assumes ...  that their lifespan are controlled by the collection.
Just in this case the items are a subset of another list (or collection if you like) that control their lifespan.

Data need to be sorted to draw the lines: