Memory leak (dynamically created components)

I am using the tWave component.
tWave is used for editing and writing sound files (.wav)

The latest version of the tWave component can be found at http://home.bip.net/baxtrom/delphi/wave.zip

The following code loads c:\hugefile.wav into memory, and that occupies 20 megabytes of memory in my case. The problem is, that the line "w.free" does not free the memory used. The memory is released when the application terminates. How can I free the memory immediately?


procedure TForm1.Button1Click(Sender: TObject);
var
  w:tWave;
begin
  w:=tWave.Create(nil);
  try
    w.FileName:='C:\HugeFile.wav'; //This file is 20 megabytes on my computer.

    //w.filename is a property. Every time it is changed the file is loaded into memory


  finally
    w.free;
  end;
end;


I wonder why tWave has no Constructor or Destructor...
hutelihutAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ziolkoCommented:
probably it's poorly written component, what you can do about it? well alter original code (if you have source files) otherwise contact creator of component.

if you decide to alter code yourself try FastMM (http://sourceforge.net/projects/fastmm/) which can help you a lot with finding memory leaks.

ziolko.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hutelihutAuthor Commented:
I just added the following lines to the component:

constructor TWave.Create(AOwner: TComponent);
begin
  FWaveStream:=nil;
  FTempWaveStream:=nil;
  Inherited Create(AOwner);
end;

destructor TWave.Destroy;
begin
  if Assigned(FWaveStream) then FWaveStream.Free;
  if Assigned(FTempWaveStream) then FTempWaveStream.free;

  FWaveStream:=nil;
  FTempWaveStream:=nil;
  Inherited Destroy;
end;

....it seems to work. I have just sent an email to the creator, and I am waiting for reply...
0
ziolkoCommented:
 if Assigned(FWaveStream) then FWaveStream.Free;
  if Assigned(FTempWaveStream) then FTempWaveStream.free;

  FWaveStream:=nil;
  FTempWaveStream:=nil;

you can do it simpler:
FreeAndNil(FWaveStream);
FreeAndNil(FTempWaveStream);

ziolko.
0
developmentguruPresidentCommented:
On thing I have seen that may help.... When I dynamically create dataset components in Delphi 2007 and pass Nil as the owner I get memory leaks.  If I pass in a form or data module then I get no leaks.  Try giving it an owner and see if it helps.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.