[Circle] Mob Progs & Memory Leaks

From: zeke (zen@nashville.com)
Date: 08/13/96

Mobprogs and how to imp them on Merc/Envy muds so I took a look and in the
context of the page I found this:

The cause of the famous 'memory leak' I believe I have tracked down. The
stock MOBprogram code loses memory when there are zones with MOBprograms on
the mobiles and no players.

I'm not sure if the circle port does this, bieng that I don't use it, but I
thought this bit of info might be helpful to those who do use mobprogs.
Here is the solution give to fix this problem of Envy 1.0:

Under Envy 1.0, I put this code into aggr_update(), after the descriptor
loop was done. This goes through all of the characters looking for
MOBprograms. I believe the 'optimization' not to do the actions when no
players were in the zone was the cause of people's 'memory leaks', theline
'(wch->in_room->area->nplayer > 0)' in the if().  See, if "the kobold leaves
north" every minute that is 25 bytes * 60min/hour or 1.5k per hour times say 10
mobiles times 100 mobprogrammed mobiles in zones without players is
1.5megs/hour of leaks. All of these mobprograms are going to fire, too, the
first time a player enters the zone, which is probably not what was intended. 

   // Now respond to MOBprograms--Slash
   for ( ch = char_list; ch != NULL; ch = wch_next )
      wch_next = ch->next;

      /* MOBProgram ACT_PROG trigger */
      if ( IS_NPC( ch ) && ch->mpactnum > 0)
         // Merc 2.2 only freed this memory when a player was in the zone, I see
         // no reason to wait for that to happen--Slash
         //     && wch->in_room->area->nplayer > 0 )
         // Examine everything the mobile heard since the last
aggr_update(),             and
         // respond to it
         MPROG_ACT_LIST * tmp_act, *tmp2_act;
         for ( tmp_act = ch->mpact; tmp_act != NULL; tmp_act = tmp_act->next )
            mprog_wordlist_check( tmp_act->buf, ch, tmp_act->ch,
tmp_act->obj, tmp_act->vo, 
               ACT_PROG );
            free_string( tmp_act->buf );
         // Free the memory allocated to the 'act() memory'
         for ( tmp_act = ch->mpact; tmp_act != NULL; tmp_act = tmp2_act )
            tmp2_act = tmp_act->next;
            free_mem( tmp_act, sizeof( MPROG_ACT_LIST ) );
         // Zap the pointer to the memory
         ch->mpactnum = 0;
         ch->mpact = NULL;

Hope this info helps the people out there suffering from memory leaks.


| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |

This archive was generated by hypermail 2b30 : 12/07/00 PST