Spelt / ZXing.Delphi

ZXing Barcode Scanning object Pascal Library for Delphi VCL and Delphi Firemonkey
Apache License 2.0
479 stars 204 forks source link

Fixed almost all memory leaks under Win32/Win64 #32

Closed csm101 closed 8 years ago

csm101 commented 8 years ago

I re-made what already did on branch Master... there were too much differences, so I did it all again. What is is still left to do: There still are memory leaks (I didn't address them yet, but they are small, compared to the ones I fixed) caused by the TReadResult class, when it uses the FResultMetadata: TDictionary<TResultMetadataType, TObject>; member variable.

Since TObjects, with old-gen compilers, are not garbage collected, it is not possible to store instance objects in that dictionary and forget about them: they will never be deallocated. That dictionary should become too a TDictionary<TResultMetadataType, IReadResultItem> where IReadResultItem should be an interface implemented by a TInterfacedObject class.

For example TStringObject (declared in the same unit) should become a TInterfacedObject descendant and it should implement a IStringResultItem interface (extended from IReadResultItem). SIDE NOTE: There is a worst problem with 64 bit compilation with version 3.0, I will write a proper bug report (or a pull request, if I will find a way to fix it): it seem that, when compiled under 64 bit, the BitMatrix instances (the result of the actual scanning of the source image) are "mangled", so the barcode scanning does not work (at least for qr-codes). I added this ToString override just for debug purposes: it dumps the bitmap as plain text. I tested the contents of the bitmatrix, while scanning the same qr-code with 32 and 64 bit and I compared them with winmerge... It seems that the first 9-10 lines of the dump are identical, then the 64 bit version starts to read "garbage" for the next 30-40 lines and then it starts again reading correctly for other 9-10 lines and it goes on like that. I suspect that it might be caused by some issues with binary-shift operators.

function TBitMatrix.ToString: string; var r,c:integer; begin for r := 0 to Fheight -1 do begin for c:= 0 to Fwidth-1 do begin if matrix[r,c] then result := result + '*' else result := result + '.'; end; result := result + #13#10; end; end;

Spelt commented 8 years ago

You are right since 3.0 there is a bug in 64bit windows.

I also will take a look.

I merged your version and uploaded it with some house keeping. I updated the readme and added the lib files to the unit test project so I could remove some unused files and this will allow for better searching.

Can you do a pull and work from there?

Op 26 aug. 2016, om 20:13 heeft Carlo Sirna notifications@github.com het volgende geschreven:

I re-made what already did on branch Master... there were too much differences, so I did it all again. What is is still left to do: There still are memory leaks (I didn't address them yet, but they are small, compared to the ones I fixed) caused by the TReadResult class, when it uses the FResultMetadata: TDictionary<TResultMetadataType, TObject>; member variable.

Since TObjects, with old-gen compilers, are not garbage collected, it is not possible to store instance objects in that dictionary and forget about them: they will never be deallocated. That dictionary should become too a TDictionary where IReadResultItem should be an interface implemented by a TInterfacedObject class.

For example TStringObject (declared in the same unit) should become a TInterfacedObject descendant and it should implement a IStringResultItem interface (extended from IReadResultItem). SIDE NOTE: There is a worst problem with 64 bit compilation with version 3.0, I will write a proper bug report (or a pull request, if I will find a way to fix it): it seem that, when compiled under 64 bit, the BitMatrix instances (the result of the actual scanning of the source image) are "mangled", so the barcode scanning does not work (at least for qr-codes). I added this ToString override just for debug purposes: it dumps the bitmap as plain text. I tested the contents of the bitmatrix, while scanning the same qr-code with 32 and 64 bit and I compared them with winmerge... It seems that the first 9-10 lines of the dump are identical, then the 64 bit version starts to read "garbage" for the next 30-40 lines and then it starts again reading correctly for other 9-10 lines and it goes on like that. I suspect that it might be caused by some issues with binary-shift operators.

function TBitMatrix.ToString: string; var r,c:integer; begin for r := 0 to Fheight -1 do begin for c:= 0 to Fwidth-1 do begin if matrix[r,c] then result := result + '*' else result := result + '.'; end; result := result + #13 https://github.com/Spelt/ZXing.Delphi/issues/13#10; end; end;

You can view, comment on, or merge this pull request online at:

https://github.com/Spelt/ZXing.Delphi/pull/32 https://github.com/Spelt/ZXing.Delphi/pull/32 Commit Summary

Fixed almost all memory leaks under old gen compilers (Win32/Win64) and some potential "dangling pointer" references Merge branch 'v_3.0' of https://github.com/Spelt/ZXing.Delphi into v_3.0 File Changes

M Lib/Classes/1D Barcodes/ZXing.OneD.Code128Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-0 (27) M Lib/Classes/1D Barcodes/ZXing.OneD.Code93Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-1 (18) M Lib/Classes/1D Barcodes/ZXing.OneD.EAN13Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-2 (4) M Lib/Classes/1D Barcodes/ZXing.OneD.ITFReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-3 (42) M Lib/Classes/1D Barcodes/ZXing.OneD.OneDReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-4 (165) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension2Support.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-5 (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension5Support.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-6 (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtensionSupport.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-7 (4) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-8 (54) M Lib/Classes/2D Barcodes/Decoder/ZXing.Datamatrix.Internal.DecodedBitStreamParser.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-9 (2) M Lib/Classes/2D Barcodes/Decoder/ZXing.QrCode.Internal.QRCodeDecoderMetaData.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-10 (6) M Lib/Classes/2D Barcodes/Detector/ZXing.Datamatrix.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-11 (90) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-12 (76) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-13 (26) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-14 (112) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-15 (46) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-16 (95) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-17 (43) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-18 (159) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternInfo.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-19 (16) M Lib/Classes/2D Barcodes/ZXing.Datamatrix.DataMatrixReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-20 (6) M Lib/Classes/2D Barcodes/ZXing.QrCode.QRCodeReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-21 (6) M Lib/Classes/Common/Detector/ZXing.Common.Detector.WhiteRectangleDetector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-22 (150) M Lib/Classes/Common/ZXing.Common.BitArray.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-23 (452) A Lib/Classes/Common/ZXing.Common.BitArrayImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-24 (479) M Lib/Classes/Common/ZXing.Common.BitMatrix.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-25 (34) M Lib/Classes/Common/ZXing.Common.DetectorResult.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-26 (8) M Lib/Classes/Common/ZXing.ReadResult.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-27 (35) M Lib/Classes/Common/ZXing.ResultPoint.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-28 (220) A Lib/Classes/Common/ZXing.ResultPointImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-29 (168) M Lib/Classes/Filtering/Binarizer.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-30 (2) M Lib/Classes/Filtering/BinaryBitmap.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-31 (4) M Lib/Classes/Filtering/GlobalHistogramBinarizer.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-32 (8) M Lib/Classes/Filtering/ZXing.BaseLuminanceSource.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-33 (6) Patch Links:

https://github.com/Spelt/ZXing.Delphi/pull/32.patch https://github.com/Spelt/ZXing.Delphi/pull/32.patch https://github.com/Spelt/ZXing.Delphi/pull/32.diff https://github.com/Spelt/ZXing.Delphi/pull/32.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/pull/32, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1Rm9DMWxRiTXNynZr6uu4BLgQGYyks5qjyzYgaJpZM4JuVG2.

Spelt commented 8 years ago

I did a new push. Forgot some things.

Op 26 aug. 2016, om 21:49 heeft Edward Spelt edwardspelt@gmail.com het volgende geschreven:

You are right since 3.0 there is a bug in 64bit windows.

I also will take a look.

I merged your version and uploaded it with some house keeping. I updated the readme and added the lib files to the unit test project so I could remove some unused files and this will allow for better searching.

Can you do a pull and work from there?

Op 26 aug. 2016, om 20:13 heeft Carlo Sirna <notifications@github.com mailto:notifications@github.com> het volgende geschreven:

I re-made what already did on branch Master... there were too much differences, so I did it all again. What is is still left to do: There still are memory leaks (I didn't address them yet, but they are small, compared to the ones I fixed) caused by the TReadResult class, when it uses the FResultMetadata: TDictionary<TResultMetadataType, TObject>; member variable.

Since TObjects, with old-gen compilers, are not garbage collected, it is not possible to store instance objects in that dictionary and forget about them: they will never be deallocated. That dictionary should become too a TDictionary where IReadResultItem should be an interface implemented by a TInterfacedObject class.

For example TStringObject (declared in the same unit) should become a TInterfacedObject descendant and it should implement a IStringResultItem interface (extended from IReadResultItem). SIDE NOTE: There is a worst problem with 64 bit compilation with version 3.0, I will write a proper bug report (or a pull request, if I will find a way to fix it): it seem that, when compiled under 64 bit, the BitMatrix instances (the result of the actual scanning of the source image) are "mangled", so the barcode scanning does not work (at least for qr-codes). I added this ToString override just for debug purposes: it dumps the bitmap as plain text. I tested the contents of the bitmatrix, while scanning the same qr-code with 32 and 64 bit and I compared them with winmerge... It seems that the first 9-10 lines of the dump are identical, then the 64 bit version starts to read "garbage" for the next 30-40 lines and then it starts again reading correctly for other 9-10 lines and it goes on like that. I suspect that it might be caused by some issues with binary-shift operators.

function TBitMatrix.ToString: string; var r,c:integer; begin for r := 0 to Fheight -1 do begin for c:= 0 to Fwidth-1 do begin if matrix[r,c] then result := result + '*' else result := result + '.'; end; result := result + #13 https://github.com/Spelt/ZXing.Delphi/issues/13#10; end; end;

You can view, comment on, or merge this pull request online at:

https://github.com/Spelt/ZXing.Delphi/pull/32 https://github.com/Spelt/ZXing.Delphi/pull/32 Commit Summary

Fixed almost all memory leaks under old gen compilers (Win32/Win64) and some potential "dangling pointer" references Merge branch 'v_3.0' of https://github.com/Spelt/ZXing.Delphi https://github.com/Spelt/ZXing.Delphi into v_3.0 File Changes

M Lib/Classes/1D Barcodes/ZXing.OneD.Code128Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-0 (27) M Lib/Classes/1D Barcodes/ZXing.OneD.Code93Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-1 (18) M Lib/Classes/1D Barcodes/ZXing.OneD.EAN13Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-2 (4) M Lib/Classes/1D Barcodes/ZXing.OneD.ITFReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-3 (42) M Lib/Classes/1D Barcodes/ZXing.OneD.OneDReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-4 (165) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension2Support.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-5 (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension5Support.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-6 (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtensionSupport.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-7 (4) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-8 (54) M Lib/Classes/2D Barcodes/Decoder/ZXing.Datamatrix.Internal.DecodedBitStreamParser.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-9 (2) M Lib/Classes/2D Barcodes/Decoder/ZXing.QrCode.Internal.QRCodeDecoderMetaData.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-10 (6) M Lib/Classes/2D Barcodes/Detector/ZXing.Datamatrix.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-11 (90) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-12 (76) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-13 (26) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-14 (112) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-15 (46) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-16 (95) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-17 (43) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-18 (159) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternInfo.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-19 (16) M Lib/Classes/2D Barcodes/ZXing.Datamatrix.DataMatrixReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-20 (6) M Lib/Classes/2D Barcodes/ZXing.QrCode.QRCodeReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-21 (6) M Lib/Classes/Common/Detector/ZXing.Common.Detector.WhiteRectangleDetector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-22 (150) M Lib/Classes/Common/ZXing.Common.BitArray.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-23 (452) A Lib/Classes/Common/ZXing.Common.BitArrayImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-24 (479) M Lib/Classes/Common/ZXing.Common.BitMatrix.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-25 (34) M Lib/Classes/Common/ZXing.Common.DetectorResult.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-26 (8) M Lib/Classes/Common/ZXing.ReadResult.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-27 (35) M Lib/Classes/Common/ZXing.ResultPoint.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-28 (220) A Lib/Classes/Common/ZXing.ResultPointImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-29 (168) M Lib/Classes/Filtering/Binarizer.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-30 (2) M Lib/Classes/Filtering/BinaryBitmap.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-31 (4) M Lib/Classes/Filtering/GlobalHistogramBinarizer.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-32 (8) M Lib/Classes/Filtering/ZXing.BaseLuminanceSource.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-33 (6) Patch Links:

https://github.com/Spelt/ZXing.Delphi/pull/32.patch https://github.com/Spelt/ZXing.Delphi/pull/32.patch https://github.com/Spelt/ZXing.Delphi/pull/32.diff https://github.com/Spelt/ZXing.Delphi/pull/32.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/pull/32, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1Rm9DMWxRiTXNynZr6uu4BLgQGYyks5qjyzYgaJpZM4JuVG2.

Spelt commented 8 years ago

About the 64bit bug. I see some shr in the source which should not be there. shr in .NET is not the same as in Delphi. Tomorrow I will dig into this. It smells like something.

Spelt commented 8 years ago

Hi Carlo,

The 64bit problem has been fixed by me and is uploaded to the server, everything is working fine again. It was something that was introduced with the Datamatrix code (also a 2D code). Cause was usage of shr instead of TMathUtils.Asr(). See for a good explanation: http://galfar.vevb.net/wp/2009/shift-right-delphi-vs-c/ http://galfar.vevb.net/wp/2009/shift-right-delphi-vs-c/

Op 26 aug. 2016, om 20:13 heeft Carlo Sirna notifications@github.com het volgende geschreven:

I re-made what already did on branch Master... there were too much differences, so I did it all again. What is is still left to do: There still are memory leaks (I didn't address them yet, but they are small, compared to the ones I fixed) caused by the TReadResult class, when it uses the FResultMetadata: TDictionary<TResultMetadataType, TObject>; member variable.

Since TObjects, with old-gen compilers, are not garbage collected, it is not possible to store instance objects in that dictionary and forget about them: they will never be deallocated. That dictionary should become too a TDictionary where IReadResultItem should be an interface implemented by a TInterfacedObject class.

For example TStringObject (declared in the same unit) should become a TInterfacedObject descendant and it should implement a IStringResultItem interface (extended from IReadResultItem). SIDE NOTE: There is a worst problem with 64 bit compilation with version 3.0, I will write a proper bug report (or a pull request, if I will find a way to fix it): it seem that, when compiled under 64 bit, the BitMatrix instances (the result of the actual scanning of the source image) are "mangled", so the barcode scanning does not work (at least for qr-codes). I added this ToString override just for debug purposes: it dumps the bitmap as plain text. I tested the contents of the bitmatrix, while scanning the same qr-code with 32 and 64 bit and I compared them with winmerge... It seems that the first 9-10 lines of the dump are identical, then the 64 bit version starts to read "garbage" for the next 30-40 lines and then it starts again reading correctly for other 9-10 lines and it goes on like that. I suspect that it might be caused by some issues with binary-shift operators.

function TBitMatrix.ToString: string; var r,c:integer; begin for r := 0 to Fheight -1 do begin for c:= 0 to Fwidth-1 do begin if matrix[r,c] then result := result + '*' else result := result + '.'; end; result := result + #13 https://github.com/Spelt/ZXing.Delphi/issues/13#10; end; end;

You can view, comment on, or merge this pull request online at:

https://github.com/Spelt/ZXing.Delphi/pull/32 https://github.com/Spelt/ZXing.Delphi/pull/32 Commit Summary

Fixed almost all memory leaks under old gen compilers (Win32/Win64) and some potential "dangling pointer" references Merge branch 'v_3.0' of https://github.com/Spelt/ZXing.Delphi into v_3.0 File Changes

M Lib/Classes/1D Barcodes/ZXing.OneD.Code128Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-0 (27) M Lib/Classes/1D Barcodes/ZXing.OneD.Code93Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-1 (18) M Lib/Classes/1D Barcodes/ZXing.OneD.EAN13Reader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-2 (4) M Lib/Classes/1D Barcodes/ZXing.OneD.ITFReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-3 (42) M Lib/Classes/1D Barcodes/ZXing.OneD.OneDReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-4 (165) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension2Support.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-5 (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension5Support.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-6 (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtensionSupport.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-7 (4) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-8 (54) M Lib/Classes/2D Barcodes/Decoder/ZXing.Datamatrix.Internal.DecodedBitStreamParser.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-9 (2) M Lib/Classes/2D Barcodes/Decoder/ZXing.QrCode.Internal.QRCodeDecoderMetaData.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-10 (6) M Lib/Classes/2D Barcodes/Detector/ZXing.Datamatrix.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-11 (90) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-12 (76) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-13 (26) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-14 (112) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-15 (46) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-16 (95) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-17 (43) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-18 (159) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternInfo.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-19 (16) M Lib/Classes/2D Barcodes/ZXing.Datamatrix.DataMatrixReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-20 (6) M Lib/Classes/2D Barcodes/ZXing.QrCode.QRCodeReader.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-21 (6) M Lib/Classes/Common/Detector/ZXing.Common.Detector.WhiteRectangleDetector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-22 (150) M Lib/Classes/Common/ZXing.Common.BitArray.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-23 (452) A Lib/Classes/Common/ZXing.Common.BitArrayImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-24 (479) M Lib/Classes/Common/ZXing.Common.BitMatrix.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-25 (34) M Lib/Classes/Common/ZXing.Common.DetectorResult.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-26 (8) M Lib/Classes/Common/ZXing.ReadResult.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-27 (35) M Lib/Classes/Common/ZXing.ResultPoint.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-28 (220) A Lib/Classes/Common/ZXing.ResultPointImplementation.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-29 (168) M Lib/Classes/Filtering/Binarizer.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-30 (2) M Lib/Classes/Filtering/BinaryBitmap.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-31 (4) M Lib/Classes/Filtering/GlobalHistogramBinarizer.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-32 (8) M Lib/Classes/Filtering/ZXing.BaseLuminanceSource.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-33 (6) Patch Links:

https://github.com/Spelt/ZXing.Delphi/pull/32.patch https://github.com/Spelt/ZXing.Delphi/pull/32.patch https://github.com/Spelt/ZXing.Delphi/pull/32.diff https://github.com/Spelt/ZXing.Delphi/pull/32.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/pull/32, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1Rm9DMWxRiTXNynZr6uu4BLgQGYyks5qjyzYgaJpZM4JuVG2.

csm101 commented 8 years ago

great!

On Aug 27, 2016 1:29 PM, "E Spelt" notifications@github.com wrote:

Hi Carlo,

The 64bit problem has been fixed by me and is uploaded to the server, everything is working fine again. It was something that was introduced with the Datamatrix code (also a 2D code). Cause was usage of shr instead of TMathUtils.Asr(). See for a good explanation: http://galfar.vevb.net/wp/ 2009/shift-right-delphi-vs-c/ http://galfar.vevb.net/wp/ 2009/shift-right-delphi-vs-c/

Op 26 aug. 2016, om 20:13 heeft Carlo Sirna notifications@github.com het volgende geschreven:

I re-made what already did on branch Master... there were too much differences, so I did it all again. What is is still left to do: There still are memory leaks (I didn't address them yet, but they are small, compared to the ones I fixed) caused by the TReadResult class, when it uses the FResultMetadata: TDictionary<TResultMetadataType, TObject>; member variable.

Since TObjects, with old-gen compilers, are not garbage collected, it is not possible to store instance objects in that dictionary and forget about them: they will never be deallocated. That dictionary should become too a TDictionary where IReadResultItem should be an interface implemented by a TInterfacedObject class.

For example TStringObject (declared in the same unit) should become a TInterfacedObject descendant and it should implement a IStringResultItem interface (extended from IReadResultItem). SIDE NOTE: There is a worst problem with 64 bit compilation with version 3.0, I will write a proper bug report (or a pull request, if I will find a way to fix it): it seem that, when compiled under 64 bit, the BitMatrix instances (the result of the actual scanning of the source image) are "mangled", so the barcode scanning does not work (at least for qr-codes). I added this ToString override just for debug purposes: it dumps the bitmap as plain text. I tested the contents of the bitmatrix, while scanning the same qr-code with 32 and 64 bit and I compared them with winmerge... It seems that the first 9-10 lines of the dump are identical, then the 64 bit version starts to read "garbage" for the next 30-40 lines and then it starts again reading correctly for other 9-10 lines and it goes on like that. I suspect that it might be caused by some issues with binary-shift operators.

function TBitMatrix.ToString: string; var r,c:integer; begin for r := 0 to Fheight -1 do begin for c:= 0 to Fwidth-1 do begin if matrix[r,c] then result := result + '*' else result := result + '.'; end; result := result + #13 <https://github.com/Spelt/ZXing.Delphi/issues/13

10;

end; end;

You can view, comment on, or merge this pull request online at:

https://github.com/Spelt/ZXing.Delphi/pull/32 https://github.com/Spelt/ ZXing.Delphi/pull/32 Commit Summary

Fixed almost all memory leaks under old gen compilers (Win32/Win64) and some potential "dangling pointer" references Merge branch 'v_3.0' of https://github.com/Spelt/ZXing.Delphi into v_3.0 File Changes

M Lib/Classes/1D Barcodes/ZXing.OneD.Code128Reader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-0> (27) M Lib/Classes/1D Barcodes/ZXing.OneD.Code93Reader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-1> (18) M Lib/Classes/1D Barcodes/ZXing.OneD.EAN13Reader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-2> (4) M Lib/Classes/1D Barcodes/ZXing.OneD.ITFReader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-3> (42) M Lib/Classes/1D Barcodes/ZXing.OneD.OneDReader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-4> (165) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension2Support.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-5> (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtension5Support.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-6> (16) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANExtensionSupport.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-7> (4) M Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-8> (54) M Lib/Classes/2D Barcodes/Decoder/ZXing.Datamatrix.Internal.DecodedBitStreamParser.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-9 (2) M Lib/Classes/2D Barcodes/Decoder/ZXing.QrCode.Internal.QRCodeDecoderMetaData.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-10 (6) M Lib/Classes/2D Barcodes/Detector/ZXing.Datamatrix.Internal.Detector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-11 (90) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-12 (76) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.AlignmentPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-13 (26) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal. AlignmentPatternImplementation.pas https://github.com/Spelt/ ZXing.Delphi/pull/32/files#diff-14 (112) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.Detector.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-15> (46) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPattern.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-16 (95) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternFinder.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-17 (43) A Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal. FinderPatternImplementation.pas https://github.com/Spelt/ ZXing.Delphi/pull/32/files#diff-18 (159) M Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.FinderPatternInfo.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-19 (16) M Lib/Classes/2D Barcodes/ZXing.Datamatrix.DataMatrixReader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-20> (6) M Lib/Classes/2D Barcodes/ZXing.QrCode.QRCodeReader.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-21> (6) M Lib/Classes/Common/Detector/ZXing.Common.Detector.WhiteRectangleDetector.pas https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-22 (150) M Lib/Classes/Common/ZXing.Common.BitArray.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-23> (452) A Lib/Classes/Common/ZXing.Common.BitArrayImplementation.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-24> (479) M Lib/Classes/Common/ZXing.Common.BitMatrix.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-25> (34) M Lib/Classes/Common/ZXing.Common.DetectorResult.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-26> (8) M Lib/Classes/Common/ZXing.ReadResult.pas https://github.com/Spelt/ ZXing.Delphi/pull/32/files#diff-27 (35) M Lib/Classes/Common/ZXing.ResultPoint.pas https://github.com/Spelt/ ZXing.Delphi/pull/32/files#diff-28 (220) A Lib/Classes/Common/ZXing.ResultPointImplementation.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-29> (168) M Lib/Classes/Filtering/Binarizer.pas https://github.com/Spelt/ ZXing.Delphi/pull/32/files#diff-30 (2) M Lib/Classes/Filtering/BinaryBitmap.pas https://github.com/Spelt/ ZXing.Delphi/pull/32/files#diff-31 (4) M Lib/Classes/Filtering/GlobalHistogramBinarizer.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-32> (8) M Lib/Classes/Filtering/ZXing.BaseLuminanceSource.pas < https://github.com/Spelt/ZXing.Delphi/pull/32/files#diff-33> (6) Patch Links:

https://github.com/Spelt/ZXing.Delphi/pull/32.patch < https://github.com/Spelt/ZXing.Delphi/pull/32.patch> https://github.com/Spelt/ZXing.Delphi/pull/32.diff < https://github.com/Spelt/ZXing.Delphi/pull/32.diff> — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/Spelt/ZXing.Delphi/pull/32>, or mute the thread < https://github.com/notifications/unsubscribe-auth/ AMEt1Rm9DMWxRiTXNynZr6uu4BLgQGYyks5qjyzYgaJpZM4JuVG2>.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/pull/32#issuecomment-242911928, or mute the thread https://github.com/notifications/unsubscribe-auth/AFeJmytbx0oBvYNqWMBeWU9HiDUlvTrjks5qkB-egaJpZM4JuVG2 .