[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

my TCppWebBrowser is leaking memory

Posted on 2002-05-02
4
Medium Priority
?
469 Views
Last Modified: 2012-05-04
Hi,
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();
stm1->Write(str,StrLen(str)+1);
IPersistStreamInit *psi;
stm1->Seek(0,0);
TStreamAdapter *sa = new TStreamAdapter(stm1,soReference);
SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IPersistStreamInit,(void **)&psi));

psi->Load(*sa);
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??
0
Comment
Question by:nfredrikn
[X]
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
4 Comments
 
LVL 3

Expert Comment

by:Crius
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...
0
 
LVL 3

Accepted Solution

by:
Crius earned 900 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...
0
 

Author Comment

by:nfredrikn
ID: 6988148
Thanks,
but the reason I dont delete "sa" is because the
program crashes when I try to. Do you know what to
do about that?
0
 
LVL 3

Expert Comment

by:Crius
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...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

649 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