my TCppWebBrowser is leaking memory

Posted on 2002-05-02
Last Modified: 2012-05-04
I'm using the TCppWebBrowser in Borland C++ Builder
and I have a problem.

I load new stuff into the browser with this code:

TMemoryStream *stm1 = new TMemoryStream();
AnsiString tmpBasic = readFile("rightStartPage");

char *str = tmpBasic.c_str();
IPersistStreamInit *psi;
TStreamAdapter *sa = new TStreamAdapter(stm1,soReference);
SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IPersistStreamInit,(void **)&psi));

delete stm1;

And the program grows every time I load new stuff into
the browser. I dont know how to avoid that.

Does anyone know what I should do to avoid memoryleakage??
Question by:nfredrikn
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 6986439
Well, for one, you are doing a QueryInterface() for psi.
You need to do a psi->Release() because of that. You also need to do it on every variable you got with QueryInterface...

Accepted Solution

Crius earned 300 total points
ID: 6986454
A worse problem is I don't see where you are deleting sa. Every variable you allocate memory for using new must be deallocated with delete... somewhere...

Author Comment

ID: 6988148
but the reason I dont delete "sa" is because the
program crashes when I try to. Do you know what to
do about that?

Expert Comment

ID: 6991755
It might have something to do with the stm1 stream still being attached.

I don't know anything about TStreamAdapter, but since you called new on it, somewhere, somewhen, you will have to call delete on it, or suffer memory loss and old age...

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question