1
0
Fork 0

Working on hunting down a really awful memory leak. This arose out of a

misunderstanding over which section of code would be freeing tiles.  This
patch cleans up several things, but a little more work is still needed.
This commit is contained in:
curt 2002-08-06 18:50:12 +00:00
parent e66c57a7bb
commit 9885169964
3 changed files with 14 additions and 16 deletions

View file

@ -105,6 +105,7 @@ bool FGNewCache::exists( const SGBucket& b ) const {
}
#if 0
// Ensure at least one entry is free in the cache
bool FGNewCache::make_space() {
SG_LOG( SG_TERRAIN, SG_DEBUG, "Make space in cache" );
@ -169,6 +170,7 @@ bool FGNewCache::make_space() {
"FGNewCache::make_space()." );
return false;
}
#endif
// Return the index of the oldest tile in the cache, return -1 if
@ -246,18 +248,12 @@ void FGNewCache::clear_cache() {
bool FGNewCache::insert_tile( FGTileEntry *e ) {
// set time of insertion for tracking age of tiles...
e->set_timestamp(globals->get_sim_time_sec());
// clear out a distant entry in the cache if needed.
if ( make_space() ) {
// register it in the cache
long tile_index = e->get_tile_bucket().gen_index();
tile_cache[tile_index] = e;
return true;
} else {
// failed to find cache space
// register it in the cache
long tile_index = e->get_tile_bucket().gen_index();
tile_cache[tile_index] = e;
return false;
}
return true;
}

View file

@ -82,8 +82,10 @@ public:
// Check if the specified "bucket" exists in the cache
bool exists( const SGBucket& b ) const;
#if 0
// Ensure at least one entry is free in the cache
bool make_space();
#endif
// Return the index of the oldest tile in the cache, return -1 if
// nothing available to be removed.

View file

@ -698,21 +698,17 @@ static int fgPartialFreeSSGtree( ssgBranch *b, int n ) {
int result = fgPartialFreeSSGtree( (ssgBranch *)kid, n );
num_deletes += result;
n -= result;
if ( kid->getNumKids() == 0 ) {
b->removeKid(i);
num_deletes++;
n--;
}
if ( n < 0 ) {
break;
}
} else {
b->removeKid(i);
num_deletes++;
n--;
}
}
// remove the parent if it is empty
if ( b->getNumKids() < 0 ) {
if ( b->getNumKids() == 0 ) {
ssgDeRefDelete( b );
num_deletes++;
n--;
@ -731,6 +727,8 @@ bool FGTileEntry::free_tile() {
SG_LOG( SG_TERRAIN, SG_DEBUG,
"FREEING TILE = (" << tile_bucket << ")" );
SG_LOG( SG_TERRAIN, SG_DEBUG, "(start) free_tracker = " << free_tracker );
if ( !(free_tracker & NODES) ) {
SG_LOG( SG_TERRAIN, SG_DEBUG,
" deleting " << nodes.size() << " nodes" );
@ -792,6 +790,8 @@ bool FGTileEntry::free_tile() {
return true;
}
SG_LOG( SG_TERRAIN, SG_DEBUG, "(end) free_tracker = " << free_tracker );
// if we fall down to here, we still have work todo, return false
return false;
}