By Mode

2010-12-14 19:35:14 8 Comments

This is from a custom namespacer handler done in Delphi I use to load files into a webbrowser component.


  F: TFileStream;
  Dummy: INT64;

  F:=TFileStream.Create(strfilename fmOpenRead);
  CreateStreamOnHGlobal(0, True, DataStream);
  TOleStream.Create(DataStream).CopyFrom(F, F.Size);
  DataStream.Seek(0, STREAM_SEEK_SET, Dummy);
  TotalSize := F.Size;

The problem is that Fastmm4 gives a memory leak error when the program ends and says that TOleStream was not freed. How do I free it? If I put TOleStream in a variable and assign like this


TOS.CopyFrom(F, F.Size);


I get an error (EAccessViolation pointing to TComObject.ObjRelease in ComObj)in the end when I free the TOS variable. I would appreciate your comments and help. This problem has been bugging me for a while now.

I am also wondering if it could be something with FastMM4? Could it be giving false information? In a bit of code like the following. How is TOLEStream freed typically?


And is there a way to send data to datastream without using the TFileStream?

Hi Remy, You can find a working demo project of the namespace handler with the fastmm and the problem procedure here: When the project loads, click the button to have the namespace handler load the files. When you exit, you should get the fastmm error. Kind regards,


@Stijn Sanders 2010-12-15 07:39:07

If you need to pass an IStream interface to something, you should look into the TStreamAdapter object, you can create one on the TFileStream, and pass its IStream interface.

@Mode 2010-12-15 07:59:34

Thanks Stijn, I am going to try that

@Mode 2010-12-15 08:56:36

Thanks Stijn, Can you elaborate a little bit? When I try using Datastream:=TStreamadapter.create(f,soOwned); Fastmm4 throws an error saying I am trying to use an interface of a freed object. Some demo code would be helpful. Thanks again.

@Stijn Sanders 2010-12-17 23:22:39

I'm not sure I understand what you mean by "custom namespacer handler done in Delphi I use to load files into a webbrowser component" I don't think a custom namespace hander is the best way to load webbrowser content. There's IInternetProtocol, but that's a lot of work to implement yourself, I know because I tried here:

@Remy Lebeau 2010-12-21 10:44:01

@Mode: please show your actual code that you are having trouble with.

Related Questions

Sponsored Content

0 Answered Questions

Why Delphi program's memory continue to grow when using FastMM

1 Answered Questions

[SOLVED] How to properly free a Delphi form

  • 2017-10-03 08:01:24
  • Papaya
  • 610 View
  • 0 Score
  • 1 Answer
  • Tags:   delphi fastmm

4 Answered Questions

[SOLVED] FastMM4 says "The block header has been corrupted"

2 Answered Questions

1 Answered Questions

[SOLVED] Delphi 7 Type Library Import failing with "error accessing the OLE registry"

  • 2014-07-16 18:03:45
  • MartynA
  • 4516 View
  • 1 Score
  • 1 Answer
  • Tags:   delphi delphi-7

2 Answered Questions

[SOLVED] FastMM 64-bit "The block header has been corrupted"

  • 2014-03-12 19:01:20
  • user2091150
  • 639 View
  • 2 Score
  • 2 Answer
  • Tags:   delphi fastmm

2 Answered Questions

[SOLVED] Fixing Memory Leaks

1 Answered Questions

[SOLVED] Current FastMM release versus Delphi XE default

  • 2011-11-04 17:16:30
  • Dan Hacker
  • 2741 View
  • 3 Score
  • 1 Answer
  • Tags:   delphi fastmm

1 Answered Questions

[SOLVED] How to correctly free/finalize an ActiveX DLL in Delphi?

Sponsored Content