4D SYSTEMS FORUM

Register New Posts
 
 
 


Reply
 
Author Comment
 
ipaq3115

Avatar / Picture

Registered: 12/11/11
Posts: 139
Reply with quote  #1 
For some reason when I try to use mem_Free() my program reports -14880 in mem_Heap() and crashes shortly there after. Only happens on the second time I free this particular variable. It is loading an image.

I attached the program. The offending mem_Free() is of 'compassFile' in my touch() function.

I am setting compassFile equal to a buffer entry so that I can pass it into a piece of code I am running. Don't know if that is causing the problems or not.

 
Attached Files:
4dg comboProg.4dg (26.44 KB, 8 views)

ESPsupport

Moderator
Registered: 27/01/09
Posts: 4,279
Reply with quote  #2 
If you set one pointer to another you can only free one, if you free it twice all hell will break loose (just guessing that's what's happening)
ipaq3115

Avatar / Picture

Registered: 12/11/11
Posts: 139
Reply with quote  #3 
Yeah, I found that out when I was trying to fix this problem, but I am only trying to free one of the pointers. Will the existence of that second pointer cause problems?
meldavia

Registered: 18/03/07
Posts: 900
Reply with quote  #4 
I think you are freeing more than once.

A good practise is to zero the memory handle.

mem_Free is 'safe' to call with a variable that holds zero, eg

var mychunk;

mychunk :- mem_Alloc(1000);    // aloocate

then later.....

mem_Free(mychunk);  // free
mychunk := 0;      // protect fro inadvertent further freeing of block

.... then later

mem_Free(mychunk);  // has no effect as handle is zeroed



__________________
Regards,
Dave
ipaq3115

Avatar / Picture

Registered: 12/11/11
Posts: 139
Reply with quote  #5 
I did try zeroing out one of the pointers but I am opening two different image files. I'll make sure I zero them both when I get back to my computer tomorrow and see if that fixes it. 
ipaq3115

Avatar / Picture

Registered: 12/11/11
Posts: 139
Reply with quote  #6 
I made sure I zero both of the places where I am calling mem_Free() and I still have this problem. 

The problem does occur after I have freed and then reloaded an image.

e.g. I open the image, then I use it, free it up then go back and open it again. It is after I have freed it the second time that this happens.

I uploaded the updated version of my program, maybe you guys can spot where I'm going wrong, I can upload all the supporting files too if that would help.
ipaq3115

Avatar / Picture

Registered: 12/11/11
Posts: 139
Reply with quote  #7 
Okay, turns out after the second time I ran one of my 4fn files with file_Exec the value of my memory pointer was being changed. I checked the values, after all my code in the 4fn has run, the value is correct but after the 4fn closes and before I have run any other code, the value has changed. Doesn't seem to be anything I did.

Strange problem, but an easy enough fix by storing another copy of the pointer.
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Powered by Website Toolbox - Create a Website Forum Hosting, Guestbook Hosting, or Website Chat Room for your website.