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

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.