Advertisement

04.14.2006 at 12:11PM PDT, ID: 21814426
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

Memory leak

Asked by jasimon9 in PHP Scripting Language

Tags: , ,

I have a php script which apparently has a memory leak. Here is the relevant code:

$query = GetReallyBigQuery();
  print '<br>before SQL memory usage=' . memory_get_usage();
  $rs = SQL($query);
  $iusercnt = -1;  // used to show no rows
  if ($rs)
  {
    print '<br>after SQL memory usage=' . memory_get_usage();
    $ix = 0;
    while ($row = mysqli_fetch_row($rs))
    {
      print '<br>ix=' . $ix++ . ' memory usage=' . memory_get_usage();
      $auser[] = $row;
    }

There are three print statements that show the current memory usage. The following is the output of these print statements for the first few iterations:

before SQL memory usage=2753368
after SQL memory usage=2753368
ix=0 memory usage=2753616
ix=1 memory usage=2753912
ix=2 memory usage=2754208
ix=3 memory usage=2754504
ix=4 memory usage=2754824
ix=5 memory usage=2755144
ix=6 memory usage=2756712
ix=7 memory usage=2759272
ix=8 memory usage=2762040
ix=9 memory usage=2764816
ix=10 memory usage=2767576
ix=11 memory usage=2770336
ix=12 memory usage=2773072
ix=13 memory usage=2775832
ix=14 memory usage=2778600
ix=15 memory usage=2781336

As you can see, after the first ten or so rows, loading each row into the array takes from 2000 - 3000 bytes. There are about 10000 rows in the result set, so this runs out of memory way before completing. However, the data in the rows should be much smaller, with each row consisting of typically 150 bytes. The maximum size of the data in each row could be is about 400 bytes, as shown by the following schema (derived from selecting the data in a standalone CREATE TABLE tempname SELECT <the select statement>, and then using SHOW CREATE TABLE tempname)

HOWEVER, please note that for the vast majority of the rows, the data is much smaller than the maximum sizes.

CREATE TABLE `autoemail` (
  `usertypeid` bigint(20) unsigned NOT NULL default '0',
  `userid` mediumint(8) unsigned NOT NULL default '0',
  `dateentry` datetime default NULL,
  `dateupdate` datetime default NULL,
  `referrerid` mediumint(8) unsigned default NULL,
  `referralcnt` smallint(6) unsigned default NULL,
  `phone1` varchar(25) default NULL,
  `email1` varchar(71) default NULL,
  `status` char(1) default NULL,
  `datestatus` datetime default NULL,
  `FName` varchar(30) default NULL,
  `Password` varchar(15) NOT NULL default '',
  `LName` varchar(30) NOT NULL default '',
  `Address1` varchar(60) NOT NULL default '',
  `Address2` varchar(60) NOT NULL default '',
  `City` varchar(30) NOT NULL default '',
  `State` char(2) NOT NULL default '',
  `Postal` varchar(10) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1

The bottom line: each iteration through the loop adds about 200 bytes of data, yet the memory_get_usage function shows 2000-3000 bytes consumed.

What is causing this memory leak?Start Free Trial
[+][-]04.14.2006 at 12:49PM PDT, ID: 16456614

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: memory, bytes, out
Sign Up Now!
Solution Provided By: theonlygoodisknowledge
Participating Experts: 2
Solution Grade: B
 
 
[+][-]04.14.2006 at 02:09PM PDT, ID: 16457289

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.14.2006 at 02:19PM PDT, ID: 16457373

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.14.2006 at 03:43PM PDT, ID: 16457847

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2006 at 07:13AM PDT, ID: 16460500

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.15.2006 at 07:28AM PDT, ID: 16460561

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2006 at 03:07PM PDT, ID: 16461957

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.17.2006 at 02:39PM PDT, ID: 16472929

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2006 at 02:46PM PDT, ID: 16473022

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2006 at 08:52PM PDT, ID: 16474869

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2006 at 01:18PM PDT, ID: 16670904

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05.15.2006 at 04:38PM PDT, ID: 16686661

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43