Jump to content

allowed memory size of 985353 bytes exhausted


MasterACE14

Recommended Posts

Hello,

 

I'm receiving the following error...

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /home/ace/public_html/site/sys.php on line 342

the error is coming from the following function...

  	function getWeaponArray($Weapons,$WeaponCount ){
                $weaponA = false;
	$weaponAW=explode(";",$Weapons);
	$weaponAWC=explode(";",$WeaponCount);
	$k=0;
	for ($i=0;$i<count($weaponAW);$i++){
		for ($j=0; $j<$weaponAWC[$i] ;$j++){
			$weaponA[$k]=$weaponAW[$i]; // Line 342
			$k++;
		}
	}
	return $weaponA;
}

 

Is there a better way to write this function? or have I made a simple mistake?

 

appreciate the help.

 

Thanks, Ace

made a minor performance adjustment, still same error coming up though:

  	function getWeaponArray($Weapons,$WeaponCount ){
                $weaponA = false;
	$weaponAW=explode(";",$Weapons);
	$weaponAWC=explode(";",$WeaponCount);
	$k=0;
                $weaponAWcount = count($weaponAW); // count $weaponAW before the 'for' loop
	for ($i=0;$i<$weaponAWcount;$i++){
		for ($j=0; $j<$weaponAWC[$i] ;$j++){
			$weaponA[$k]=$weaponAW[$i]; // Line 342
			$k++;
		}
	}
	return $weaponA;
}

Unless $Weapons, $WeaponCount, $weaponAW, and $weaponAWC are large and using ~134 million bytes of memory, the problem is your overall script is using all available memory and when you attempt to create the $weaponA array, you cannot allocate enough memory.

 

What are the sizes of $Weapons and $WeaponCount? If they are fairly small, the problem is elsewhere and you would need to find where your script is using most of the memory and optimize it.

Are you reading whole (large) files into memory or returning large queries from databases and then making copies of the returned data in arrays or using a php framework or any other things that use large amounts of memory or are you using large amounts of memory but are not freeing them up once you are done with them?

 

It would take seeing your code and knowing the size of the data being used in order to help.

See if you are reading large file in memory then this is going to happen. In this case just increase the memory size for php for that script. If it is just a script that is causing the problem then check the script.

Search for PHP memory_limit .

 

ini_set('memory_limit', 'size in bytes');

 

http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-bytes

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.