The only thing I can see - a quick look only (ie it may have nothing to do with
it...)
If InitCount = 0 then the Inherited Create will not be called - No Object
Creation.
  If you then try to free it - bang !

HTH - But this is only a quick thought !!!

Regards
Paul
____________________Reply Separator____________________
Subject:  Re: [DUG]: incredible and horrible. (the Code)
Author:   [EMAIL PROTECTED]
Date:          14/11/2000 13:16



       TSpIterator = class (TObject)
       private
         NextIndexes, PrevIndexes: array of Integer;
       public
         property Count: Integer read FCount;
         property Current: Integer read FCurrent;

         constructor Create(InitCount: Integer);
         destructor Destroy; override;
         procedure Next;
         procedure Reset(NewInitCount: Integer); overload;
         procedure Reset; overload;
       end;

       TSpTransMatrix = class (TSparseMatrix)
       private
         procedure SolveDegeneration(ARow, ACol: Integer);
       public
         constructor Create(InitRows, InitCols: Integer; ANullValue: Variant);
     override;
         procedure BuildFBFSVogelsApprox( const Supplies: TSupplies;
                                          const Demands: TDemands;
                                          const Costs: TCostsMatrix);
       end;

     // TSpIterator

       constructor TSpIterator.Create(InitCount: Integer);
       begin
         if ( InitCount > 0 )
           then try
             inherited Create;
             Reset(InitCount);
               on E: EOutOfMemory do
                 MessageDlg(E.Message, mtError, [mbOk], 0);
             end
           else Free;
       end;

       procedure TSpIterator.Reset(NewInitCount: Integer);
       begin
         FCount := NewInitCount;
         SetLength(NextIndexes, NewInitCount);
         SetLength(PrevIndexes, NewInitCount);
         Reset;
       end;

       procedure TSpIterator.Reset;
         var
           i: Integer;
       begin
         FCount := Length(NextIndexes);
           NextIndexes[i] := i + 1;
           PrevIndexes[i] := i - 1;
         end;
         FirstIndex := 0;
         LastIndex := Length(NextIndexes) - 1;
       end;

       destructor TSpIterator.Destroy;
       begin
         Finalize(NextIndexes);
     Destroy;
       end;

     // TSpTransMatrix

      procedure TSpTransMatrix.BuildFBFSVogelsApprox( const Supplies: TSupplies;
                                                       const Demands: TDemands;
                                                       const Costs:
     TCostsMatrix);
         var
           TempDemands: TDemands;
           TempSupplies: TSupplies;
           RmcIndex, CmcIndex: Integer;
           RowsLeft, ColsLeft: TSpIterator;
           MinCost, SecMinCost, TempCost, MaxPenalty: Double;
           SumCheck, Diff: Double;
           i, j, mxpIndex, mxpMinCostIndex: Integer;
           mxpIndexOf: (mxpioRow, mxpioCol, mxpioNone);
       begin
         if ( (Length(Supplies) <> Rows) or (Length(Demands) <> Cols) )
           then Exit;
         Clear;
         SumCheck := 0;
         SetLength(TempDemands, Cols);   // Cols=6
     Rows);  // Rows=5 in the test data.
         RowsLeft := TSpIterator.Create(Rows); // problem starts here
         ColsLeft := TSpIterator.Create(Cols);
     begin
          // none of the code here reserves or releases any memory inside or
             // outside the SpIterators.
             // should I show it too?
         end; // ( sumcheck <> 0 )
         Finalize(TempSupplies);
         RowsLeft.Free;
       end;


     On Mon, 13 Nov 2000, Juan Manuel Gomez Ramos wrote:
     > Hi there:
     >
     >   I'm having a strange situation. I create, in a class method, two
     instances of
     > another class. At the end of the method code, I call the Free method for
     both
     > of them and, the one that was created the second, raises an
     > EInvalidPointer exception. The weird thing I see, is that after they are
     > created, both class variables have the same memory address (@Variable,
     this
     > is the horrible part). And, if I Free them right after creation, no
     exception
     > is raised (this, is the incredible part). I traced through the Destroy
     method
     > and every code line was executed correctly (some open arrays are
     Finalized),
     > except for the last one (no matter the operation), where the exception is
     > raised. If the problem occurs while accessing a pointer already disposed
     off,
     > then the exception should be raised on the second Free call but, it
     happend on
     > the class instance created the second, no matter if is freed the first.
     Every
     > thing goes ok while using the instances and their values keep different.
     I
     > wouldn't like to use the "bad practice" of letting them unreleased.
     Thanks in
     > advance.
     >
     >   Best regards, JM.
     >
     > --
     >   Juan Manuel Gomez Ramos
     >   Computer Science student at Havana University
     >   Paraglider pilot and RadioHam (CM9BPG)
     >   http://cubairsports.itgo.com = http://www.geocities.com/cubairsports
     >
     >   email:<[EMAIL PROTECTED]>         eFax: +1-707-313-0329 (USA)
     >         <[EMAIL PROTECTED]>         +44-870-125-4936 (UK)
     >         <[EMAIL PROTECTED]>
     >   ICQ:  62091995
     >   http://chronos.itgo.com
     >
     >
     >
     ---------------------------------------------------------------------------
     >     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
     >                   Website: http://www.delphi.org.nz
     > To UnSub, send email to: [EMAIL PROTECTED]
     > with body of "unsubscribe delphi"
     --
       Juan Manuel Gomez Ramos
       Computer Science student at Havana University
       Paraglider pilot and RadioHam (CM9BPG)
       http://cubairsports.itgo.com = http://www.geocities.com/cubairsports

       email:<[EMAIL PROTECTED]>         eFax: +1-707-313-0329 (USA)
             <[EMAIL PROTECTED]>         +44-870-125-4936 (UK)
             <[EMAIL PROTECTED]>
       ICQ:  62091995
       http://chronos.itgo.com


     ---------------------------------------------------------------------------
         New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                       Website: http://www.delphi.org.nz
     To UnSub, send email to: [EMAIL PROTECTED]
     with body of "unsubscribe delphi"(See attached file: att1.eml)

att1.eml

Reply via email to