Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memory problems

Status
Not open for further replies.

bubak

Programmer
Jun 25, 2001
208
SK
I have a big problem, my program works fine, but when I do one actioin e.g. 100 times, after RedrawWindow() all fonts, color,etc. get crazy, all the memory is away,... horrible things. So here are a few questions, because I don't know, what to do.
In a procedure, if I want to free the memory I do:

LPTSTR s=new char[100];
delete [] s;

CPen pen1;
pen1.CreatePen(...);
pen1.DeleteObject();

CRect aaa;
GetWindowRect(&aaa);
...is automatically destroyed on the end of the function (I hope)

CDC *dc=GetDC();
...it's destroyed automatically

Is there an error in this?
pls help
bubak
 
sorry.
problem is/was here: I use dc.selectObject(pen1), but I never do sth like pen0=dc.selectObject(pen1);
......
dc.selectObejct(pen0);
But anayway, whay does it not function automatically? ;-)

bubak
 
I think CDC* is problem because pointers are not destroyed automatically as memory allocation but only as variables. John Fill
1c.bmp


ivfmd@mail.md
 
U mena, that when I have
int aa;
void aaa(void){
int *a;
CDC *b;
char c;

a=&aa;
b=::GetDC();
c='a';
}
taht this 3 variables r not deleted when '}' is reached?


 
and one more thing: when I do old_pen=dc->selectObject(pen1); and I want also dc->SelectObject(pen2), do I have just to do it this way:
old_pen=dc->SelectObject(pen1);
dc->SelectObject(pen2); <---------------+
dc->selectObejct(old_pen); |
or do I have to put the returned |
CPen* also somewhere (from here ---------+ )
???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top