Author Topic: Collection.inc  (Read 3807 times)

HSE

  • Member
  • *****
  • Posts: 2499
  • AMD 7-32 / i3 10-64
Collection.inc
« 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:
Code: [Select]
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:
Code: [Select]
Method Collection.Free, uses esi
SetObject esi
  .if [esi].pItems != NULL
  MemFree [esi].pItems
.endif
MethodEnd

Regards. HSE
 
Equations in Assembly: SmplMath

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1083
  • ObjAsm Developer
    • ObjAsm
Re: Collection.inc
« Reply #1 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.

Code: [Select]
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

HSE

  • Member
  • *****
  • Posts: 2499
  • AMD 7-32 / i3 10-64
Re: Collection.inc
« Reply #2 on: July 28, 2017, 01:21:25 AM »
Perfect! Thanks.

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:
Equations in Assembly: SmplMath