Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cvSetMemoryManager raised Exception #135

Open
hafedh-trimeche opened this issue Aug 28, 2020 · 5 comments
Open

cvSetMemoryManager raised Exception #135

hafedh-trimeche opened this issue Aug 28, 2020 · 5 comments

Comments

@hafedh-trimeche
Copy link

Wanting intercept memory allocate & free, the cvSetMemoryManager is used. But exception raised:
External exception E06D7363

function far_alloc(size:size_t;userdata:Pointer):Pointer;cdecl;
begin
  Result := AllocMem(Size);
end;

function far_free(pptr:Pointer;userdata:Pointer):Integer;cdecl;
begin
  Result := FreeMemory(pptr);
end;

constructor TOpenCV.Create;
begin
  inherited;
  if not MemoryManagerSet then
  begin
    cvSetMemoryManager(@far_alloc,@far_free,nil);
    MemoryManagerSet := True;
  end;
end;
@Laex
Copy link
Owner

Laex commented Mar 12, 2021

I think that the ways of working with memory (managers) in C and Delphi are different (always your "Captain Obvious"). In addition, inside the dll (for OpenCV), functions also allocate and free memory for their needs (for example, for auxiliary structures and, possibly, classes). The C allocator works by knowing how to properly allocate memory for C structures and how to properly initialize memory. The Delphi allocator doesn't know.
We need to figure it out ...

@hafedh-trimeche
Copy link
Author

Hello,
Thank you for your response.

But how to debug an eventual Memory Leak?

Best regards.

@Laex
Copy link
Owner

Laex commented Mar 12, 2021

First you need to try to establish where this memory leak occurs, for example, by setting
ReportMemoryLeaksOnShutdown: = True;
Additionally, you can use some "expert", for example EurekaLog or madExcept. They show detailed information about memory leaks.

@hafedh-trimeche
Copy link
Author

Dear,

This procedure is applicable to Memory allocated by Delphi via FastMM not for External DLL written into another language.

Would Alignment {$ALIGN} or/and {$ENUMSIZE} be the cause of the problem?

Best regards.

@Laex
Copy link
Owner

Laex commented Mar 12, 2021

cvSetMemoryManager installs memory manager for functions from OpenCV (i.e. for functions from DLL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants