Article View: pilot.programmer.codewarrior
Article #23Re: char* memory leak with emulator 3.5
From: Baxter
Date: Mon, 07 Oct 2002 14:15
Date: Mon, 07 Oct 2002 14:15
61 lines
3130 bytes
3130 bytes
Somewhere in your code, you need a:
delete psaStr;
--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------
"David Ladanyi" <david_ladanyi@yahoo.com> wrote in message
news:30890494.0210062256.7a8a8fa@posting.google.com...
> Hi
>
> I have a program that seems to run fine in the emulator except that
> whenever I try to close the program I'm told that I have a memory
> leak. I've figured out what statement is causing the leak but I can't
> figure out how to fix it. This code is called when a certain form is
> being initialized:
>
> double psaVal = pronData->pretx_psa;
> char* psaStr = new char[6];
>
> if(psaVal != NO_VALUE) {
> doubleToStr(psaStr, psaVal, 1);
> }
> else
> psaStr = "";
>
> SetFieldHandle(GetObjectPtr<FieldType>( PreTxPSAField), psaStr);
>
> This code simply creates a string from a double and sets a field to
> that string. The memory leak was caused by the "new char[6]" line so I
> put in a deallocation function that would be called when the form
> receives a frmCloseEvent (I made sure to set handled=false):
>
> void PreTxCleanUp() {
>
> FormType* frmP = FrmGetActiveForm();
> FieldType* field = (FieldType*)
> FrmGetObjectPtr(frmP,FrmGetObjectIndex (frmP, PreTxPSAField));
>
> MemHandle refs = FldGetTextHandle(field);
>
> if(refs != NULL) {// && MemHandleUnlock(refs) != memErrInvalidParam)
> {
> FldSetTextHandle (field, NULL);
> MemHandleFree(refs);
> }
>
> }
>
> This function doesnt give any errors buy it also doesn't fix the
> problem. Every time I open and close the form in question it creates a
> leaked memory chunk. Am I not de-allocating the memory properly or is
> there a problem with the emulator? Also, if the memory leak is caused
> by a variable local to a certain form why isn't the emulator telling
> me about the leak as soon as I close the form as opposed to waiting
> until I close the whole program? Thanks in advance for any advice.
>
> Dave
Technical Details
Message-ID:
<uq35nhqhshk23@corp.supernews.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mailReferences:
<30890494.0210062256.7a8a8fa@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109d41,fc0bc5958a8d445f X-Google-Attributes: gid109d41,public X-Google-Thread: 10baa0,fc0bc5958a8d445f X-Google-Attributes: gid10baa0,public X-Google-ArrivalTime: 2002-10-07 07:16:54 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Baxter" <baxter.spamblock@baxcode.com> Newsgroups: pilot.programmer.codewarrior,codewarrior.palm Subject: Re: char* memory leak with emulator 3.5 Date: Mon, 7 Oct 2002 07:15:11 -0700 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <uq35nhqhshk23@corp.supernews.com> References: <30890494.0210062256.7a8a8fa@posting.google.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Complaints-To: abuse@supernews.com Lines: 63