memory leak

Discussion in 'Mac Programming' started by farmerdoug, Apr 13, 2010.

  1. farmerdoug macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    I supposedly have a memory leak on this line.


    if ((tempimage = calloc(reduced_image*2, sizeof(float))) == NULL)

    Its in getmemory on line 1015 of main; tempimage is declared on line 27; getmemory is called on line 79. reduced_image is defined in p1640.h on line 48

    Any help would be appreciated.
     

    Attached Files:

  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Explain how you know there's a memory leak, and how you know it's on that line.

    If there's a tool you used to tell you there's a leak there, what is it?

    If there's some other way you learned there's a leak, what is it?
     
  3. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #3
    I learned from running the code with Instruments checking for leaks. I also found the problem. I'll be glad to let you know but you may want to figure it out for yourself. I did have another piece of information: The code died with a trying to free unallocated memory error which I was able to track down.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    I already knew what was happening before I replied. I wanted to know how you knew.

    By the way, you should learn to use local variables by default, instead of starting with a global variable. It would have avoided this problem entirely.

    A notable number of problems you've posted about involve improper use of globals. This one is just the latest. The one before it was the use of global indexes in a multi-threaded context. In short, some basic improvements to your coding skills would greatly improve your code quality.
     
  5. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #5
    No doubt. I've never made the claim to be a programmer as you know. I'm still working on the solution to the problem itself which is why I am grateful for all the programming help I can get. Please, if you see any ways to improve and most importantly speed up the program it would be very helpful. It takes about 24 hours on my four core machine to process one ring ( the next to smallest) of out 5 (I think) that need to be processed; and this is just for one image. I have hundreds if not thousands of images to do.
     
  6. GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #6
    Dude, it sounds like you need to hire a REAL programmer. I'm sure your expertise lies in some other field, so it would be to your benefit to have you focus your time and energy on those areas where you're specialized and to hire an expert to handle your optimization needs: it's more cost effective this way. I've been learning this stuff for a while now, and I would hire a programmer in a heartbeat for a job like that, because I know it's beyond my skills.

    If money is an issue, you would be better off spending your time fundraising than trying to do hardcore performance optimizations concurrently on large data-sets with little-to-no experience/knowledge. Perhaps you could find some grad students at a nearby college who'd be willing to work for a bit less than standard industry rates. I don't know all of the details of your situation, and this is just my opinion; it's intended to be advice, not to be mean, insulting or rude, so please don't take it that way.
     
  7. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #7
    You're not being rude, mean or insulting. I would love to find somebody else to do this. I can usually muddle through but this is the biggest, hardest problem of this type that I've ever taken on. I do get help from this forum and from other colleagues. Money is of course an issue, but the funds usually end up somewhere else. I'm in NYC, if you want to volunteer.
     

Share This Page