Steve,

for kicks, do the following:

void deAllocSource()
{
    UInt16 index ;
    UInt16 err;
     char a[100];

       for (index = 0; index < 100; index++)
    {

      if (sourcel[index] != NULL) {
              err = MemPtrFree(sourcel[index]);
              ErrFatalDisplayIf(err, "problem with memptrfree'ing one of the sourcel 
array members");
              err = MemPtrFree(sourcelist[index]);
              ErrFatalDisplayIf(err, "problem with memptrfree'ing one of the source 
strings");
      }

    }
    g_source_array_count = 0;
    return;
}

I only recommend this because you don't mention how you allocate the 
array (whether or not you fill holes or just add to the end of the array 
when removing adding strings) and you don't mention how you increment, 
decrement g_source_array_count in your allocation routine when adding 
strings (is the the number of
elements in the array, or is it the max element in the array)....

I suspect that your intermitent errors are a result of removing items 
from the array, your not compressing the array, and g_source_array_count 
isn't the MAX element, it's the number of elements in the array.

Now, if I'm all off base here, you can see how hard it is to answer 
folks questions when they don't explain EVERYTHING related to the 
problem (which of course is pretty impossible...but, we do the best we 
can..)

Cheers and Good luck!

James

Steve Bailey wrote:

>Hi group, got a question on global arrays that may be causing problems.
>
> In globals.h, I have one defined as
>
>            extern char *sourcelist[100];
>
>In main.c, I declare it, and initialize it:
>
>           char *sourcelist[]  = {0};    // there's probably a better way
>
>
>I use this array of char pointers everywhere, in all of my c files, of
>course.
>
>
> In mainforminit(), I fill it up with some srings,
>
>             sourcelist[index] = MemPtrNew(StrLen(theCat.catname) + 1);
>             StrCopy( sourcelist[index], theCat.catname );
>                               // ( theCat contains a structure just
>retrieved from
>                               // database, and catname is a string of
>course )
>
>
>And in other modules, I'll do things like erase one of the elements in the
>array with
>memptrfree, and then call MemPtrNew to reallocate and throw another string
>in there, etc...
>
>When my app is closed, I have a deAllocSource function that loops through
>the array of pointers, and calls
>MemPtrFree on every one, but I'm still intermittenly getting memory leakage
>errors when closing my app on the
>debug ROM. (using new POSE version, which tells me where I'm allocating the
>part of the memory that is leaking, but I still can't find the problem
>anyway)
>
>
>void deAllocSource()
>{
>    UInt16 index ;
>    UInt16 err;
>     char a[100];
>
>       for (index = 0; index < g_source_array_count; index++)
>    {
>
>      err = MemPtrFree(sourcel[index]);
>      ErrFatalDisplayIf(err, "problem with memptrfree'ing one of the sourcel
>array members");
>      err = MemPtrFree(sourcelist[index]);
>      ErrFatalDisplayIf(err, "problem with memptrfree'ing one of the source
>strings");
>
>
>    }
>      g_source_array_count = 0;
>      return;
>}
>
>
>Do you see a problem with using an array of pointers as a global variable
>like this?
>
>Thanks for reading this, would appreciate a hint if you have one
>Steve
> p.s., using PALMOS 3.5 sdk with CW 6.0
>


-- 
------------------------------------------------------------------------
James Barwick
VP Technology

????????????
?????????????????
Sentient Health Japan, KK
Aoyama Palacio Tower 11F
3-6-7 Kita-Aoyama
Minatu-ku, Tokyo 107-0061

????????????????????
?107-0061 ???????3-6-7
????????? 11?
Tel: (03) 5778-7524
Fax: (03) 5778-7676
mailto:[EMAIL PROTECTED]
http://www.sentienthealth.com
Tel: (03) 5778-7524
Fax: (03) 5778-7676
mailto:[EMAIL PROTECTED]
http://www.sentienthealth.com
------------------------------------------------------------------------


_
_




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to