my TCppWebBrowser is leaking memory

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??
Who is Participating?
CriusConnect With a Mentor Commented:
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...
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...
nfredriknAuthor Commented:
but the reason I dont delete "sa" is because the
program crashes when I try to. Do you know what to
do about that?
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...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.