OBJ_DATA *new_obj(void)
{
static OBJ_DATA obj_zero;
OBJ_DATA *obj;
if (obj_free == NULL)
obj = alloc_perm(sizeof(*obj));
else
{
obj = obj_free;
obj_free = obj_free->next;
}
*obj = obj_zero;
VALIDATE(obj);
memset(obj, 0, sizeof(*obj));
return obj;
}
memset(obj, 0, sizeof(*obj));that's where it is no longer valid.
OBJ_DATA *new_obj (void)
{
static OBJ_DATA obj_zero;
OBJ_DATA *obj;
if (obj_free == NULL)
obj = alloc_perm (sizeof (*obj));
else
{
obj = obj_free;
obj_free = obj_free->next;
}
*obj = obj_zero;
VALIDATE (obj);
return obj;
}
I was having a problem with our mem% getting too high… after about a week or so, the MUD would crash because it ran out of available memory. I narrowed down to a function we had running every area update which would run through the entire MUD, destroy all of the "buried treasure" and go back through and place new treasure. This meant about 300 objects being destroyed then created every area update.
After some more investigating, Midboss concluded that it was likely that the objects weren't being freed properly upon being destroyed, and so that memory was still in use and the new objects were taking up new memory.
I put in some bug calls in the purge, extract_obj, and free_obj functions in order to track how far each function was making it, and I found that at the top of free_obj there is this check:
That's where the free_obj function was stopping, so all of the memory freeing that is done lower in the function wasn't being done.
I went back as far as the purge function and put in this check:
And the object was not considered valid. At the top of extract_obj, I added this:
And now the free_obj function is making it all the way to the bottom.
After doing that, I compared previous memory % when calling the bury_treasure command 100 times with current memory %, and it has dropped dramatically.
Again, I'm not sure if this was just a problem my game was having, but I thought I would post this as an alert that others might want to double check that their free_obj functions are making it to the bottom and actually freeing the memory. The function we had running is a bit of an extreme example, and I doubt too many other games have something running like that which would cause a problem like we were having, but just in case, I thought I would post this. Didn't think it would hurt for the RaM guys to see this either.
Also, on the off chance I've potentially messed something up by validating the obj at the top of extract_obj, it wouldn't hurt to have someone set me straight on that :p