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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 120
How to convert MFC APP to Win32 APP. 19 79
Header of docx file 17 102
trigs fail! I thought I knew how to do trignometry 3 65
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

786 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