Need Memory Leak Help


M

Mike

have a php page that is leaking pretty bad. I'm not sure if this
belongs in this group or a php one but I don't think it's the php that
giving me problems. I've tried to use tools like drip and sieve to
help narrow the problem down, but I'm not exactly sure how to fix it.
I've tried nulling and deleting variables to clean stuff up but it's
still not helping. Can someone give me a hand at cleaning my code up?
I'm fairly new at the mem leak stuff. Thanks.

Sorry for the large amount of code.

<?php
include_once $_SERVER["DOCUMENT_ROOT"] . "/include/header.php";
include_once $_SERVER["DOCUMENT_ROOT"] . "/include/dbfunctions.php";
header("Cache-Control: no-cache"); //needed because IE likes to cache
stuff
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<meta http-equiv="refresh" content="3600">
<html xmlns:"http://www.w3.org/1999/xhtml">

<script type="text/javascript" src="/scripts/sortabletables.js"></
script>
<script type="text/javascript" src="/scripts/reverse.js"></script>

<script type="text/javascript">

var updateTopObj;
var day = $.getUrlParameter("day");
var page = $.getUrlParameter("page");

$(document).ready(function(){

updateTopObj = new UpdatablePage({
updateFunction: updateTop,
interval: 4000,
dataType: "xml",
url: "/resources/Events.xml"
});

updateTopObj.update();
updateTopObj.start();

$('#EventsTable').styleTable({});
$('.table-sortable').click(function(){
$('tr','#EventsTable').removeClass("odd").removeClass("even");
$('#EventsTable').styleTable({});
parent.OMC.pause(frameId);
});

}); // end $(document).ready

function updateTop(xml){

var $xml = $(xml);
var $root = $('eventsInfoTable', $xml);
var $numDays = $('eventRec', $root).length; // alert($numDays);

var $dayMenuTable = $('#DayMenuTable');
var $dayMenuBody = $('tbody',$dayMenuTable).empty();
var $newDayRow = $('<tr></tr>').appendTo($dayMenuBody);

var $date_xml = $('date',$root);
var $index_xml = $('dayIndex', $root);
var $pages_xml = $('numPages', $root);
var $records_xml = $('numRecords', $root);
var date_arr = [];
var index_arr = [];
var page_arr = [];
var records_arr = [];

$('eventRec',$root).each(function(i){
$date_xml = $('date',this).text().substring(0,5); // only show dd/
mm
date_arr = $date_xml;
$index_xml = $('dayIndex',this).text();
index_arr = $index_xml;
$page_xml = $('numPages',this).text();
page_arr = $page_xml;
$records_xml = $('numRecords',this).text();
records_arr = $records_xml;
});

for(i=0; i<date_arr.length; i++){
if(date_arr != "00/00"){
$dayParam = index_arr;
}
}

if(!day){ day = $dayParam;}
for(i=date_arr.length-1; i>=0; i--){
if(date_arr != "00/00") { // don't display 00/00 dates
$topPageNum = parseInt(page_arr)-1;
//alert(index_arr+" : "+day);
if(index_arr == day){
if(!page){page = page_arr-1;}
$cell = $('<td width=45><a href="/webpage/events.php?day=' +
index_arr + '&page=' + $topPageNum + '" class="submenuSelected"
onclick="parent.OMC.play(frameId);">' + date_arr + '</a></
td>').appendTo($newDayRow);
$('#dayTitle').empty().append(date_arr+' Events Log');
} else $cell = $('<td width=45><a href="/webpage/events.php?
day=' + index_arr + '&page=' + $topPageNum + '"
class="submenuNormal" onclick="parent.OMC.play(frameId);">' + date_arr
+ '</a></td>').appendTo($newDayRow);
} //end if date != 00/00
}

//alert("DAY"+day+"_PG"+page);
$cell = $('<td><form action="CSV.php" target="_blank"
method="GET"><input type="submit" class="genCSVLink" value="View
Weekly CSV"/></form></td>').appendTo($newDayRow);

var $pageMenuTable = $('#PageMenuTable');
var $pageMenuBody = $('tbody',$pageMenuTable).empty();
var $newPageRow = $('<tr></tr>').appendTo($pageMenuBody);

for(i=date_arr.length-1; i>=0; i--){
if(index_arr == day){
$totalPages = parseInt(page_arr);
$pageInc = 20;
$totalInc = parseInt(($totalPages-1)/$pageInc)+1; //
$totalPages -1 for incase there are 20 pages exactly
//$currentPage = parseInt(page_arr)-parseInt(page);
$currentPage = parseInt(page)+1;
$currentInc = parseInt(($currentPage-1)/$pageInc) + 1; //
$currentPages -1 for incase there are 20 pages exactly
if($currentInc != 1){
$prevPage = ($currentInc-1)*$pageInc-1;
$cell = $('<td width=20><a href="/webpage/events.php?day=' +
index_arr + '&page=' + $prevPage + '" class="submenuNormal"
onclick="parent.OMC.play(frameId);">Prev</a></td>').appendTo
($newPageRow);
}
for(j=0; j<=page_arr-1; j++){
$pageNum = parseInt(j)+1;
//$pageNum = $totalPages - parseInt(j);
if(($pageNum >= ($currentInc*$pageInc)-$pageInc+1) &&
($pageNum <= ($currentInc*$pageInc))){
if($pageNum == $currentPage){
$cell = $('<td width=20><a href="/webpage/events.php?
day=' + index_arr + '&page=' + j + '" class="submenuSelected"
onclick="parent.OMC.play(frameId);">' + $pageNum + '</a></
td>').appendTo($newPageRow);
} else{
$cell = $('<td width=20><a href="/webpage/events.php?
day=' + index_arr + '&page=' + j + '" class="submenuNormal"
onclick="parent.OMC.play(frameId);">' + $pageNum + '</a></
td>').appendTo($newPageRow);

}
}
}
if($currentInc != $totalInc){
$nextPage = ($currentInc*$pageInc);
$cell = $('<td width=20><a href="/webpage/events.php?day=' +
index_arr + '&page=' + $nextPage + '" class="submenuNormal"
onclick="parent.OMC.play(frameId);">Next</a></td>').appendTo
($newPageRow);
}
if($currentPage == $totalPages){
if(records_arr == 0){
var $startRecord = 0;
var $endRecord = 0;
} else{
var $startRecord = ($currentPage-1)*100+1;
var $endRecord = records_arr;
}
} else if($totalPages == 0){
var $startRecord = 0;
var $endRecord = 0;
}
else{
var $startRecord = ($currentPage-1)*100+1;
var $endRecord = ($currentPage)*100;
}
$('#RecordsMenuTable').empty().append('Displaying records ' +
$startRecord + ' to ' + $endRecord + ' of ' + records_arr);
}
}

// make events table
$.ajax({
type: "GET",
url: "/resources/DAY"+day+"_PG"+page+".xml",
dataType: "xml",
success: function(xml){
var $eventsXml = $(xml);
var $eventsRoot = $('eventsTable', $eventsXml);
var eventsBody = document.getElementById('EventsBody');
var numNewRows = $('eventRec', $eventsRoot).length;

var $currentRows = $('tr', $(eventsBody));
var numRows = $currentRows.length;

$('th', $('#EventsTable')).removeClass("table-sorted-
asc").removeClass("table-sorted-desc");
var docFragment = document.createDocumentFragment();

var newTable = false;
//alert(numNewRows+" : "+numRows);

//If we have more rows to append than exist, re-create the
entire table
if(numNewRows != numRows){
$(eventsBody).empty();
newTable = true;
//alert("need new table");
}
//else{alert("don't need new table");}

var trElem, tdElem;

$('eventRec', $eventsRoot).reverse();

if(newTable) {
$('eventRec', $eventsRoot).each(function(i){
$record = $(this);
//alert($(this).text());
trElem = document.createElement('tr');
docFragment.appendChild(trElem);
$record.children('dateTime').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
tdElem.innerHTML = $(this).text();
});
$record.children('type').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
tdElem.innerHTML = $(this).text();
});
$record.children('source').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
tdElem.innerHTML = $(this).text();
});
$record.children('eventId').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
tdElem.innerHTML = $(this).text();
});
$record.children('assAlrm').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
tdElem.innerHTML = $(this).text();
});
$record.children('username').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
tdElem.innerHTML = $(this).text();
});
$record.children('desc').each(function(i) {
tdElem = document.createElement('td');
trElem.appendChild(tdElem);
var cellText = $(this).text();
$('bullet', $(this)).each(function(i){
tempText = $(this).text();
cellText = cellText.replace($(this).text
(),"<br>&bull;"+tempText);
});
tdElem.innerHTML = cellText;
});
eventsBody.appendChild(docFragment);
});
}

if(newTable) {
eventsBody.appendChild(docFragment);
$('#EventsTable').styleTable({header:false, title:false});
} else {}

trElem = null;
delete trElem;
tdElem = null;
delete tdElem;
numNewRows = null;
delete numNewRows;
numRows = null;
delete numRows;
newTable = null;
delete newTable;
cellText = null;
delete cellText;
$eventsRoot = null;
delete $eventsRoot;
$eventsXml = null;
delete $eventsXml;
eventsBody = null;
delete eventsBody;
$record = null;
delete $record;
cellText = null;
delete cellText;
}
});

$xml = null;
delete $xml;
$root = null;
delete $root;
$numDays = null;
delete $numDays;

$dayMenuTable = null;
delete $dayMenuTable;
$dayMenuBody = null;
delete $dayMenuBody;
$newDayRow = null;
delete $newDayRow;

$date_xml = null;
delete $date_xml;
$index_xml = null;
delete $index_xml;
$page_xml = null;
delete $page_xml;
$records_xml = null;
delete records_xml;

date_arr = null;
delete date_arr;
index_arr = null;
delete index_arr;
page_arr = null;
delete page_arr;
records_arr = null;
delete records_arr;

dayParam = null;
delete dayParam;
topPageNum = null;
delete topPageNum;
i = null;
delete i;

$pageMenuTable = null;
delete $pageMenuTable;
$pageMenuBody = null;
delete pageMenuBody;
$newPageRow = null;
delete newPageRow;

$totalPages = null;
delete $totalPages;
$pageInc = null;
delete $pageInc;
$totalInc = null;
delete $totalInc;
$currentPage = null;
delete $currentPage;
$currentInc = null;
delete $currentInc;
$prevPage = null;
delete $prevPage;
j = null;
delete j;
$pageNum = null;
delete $pageNum;
$cell = null;
delete $cell;
$nextPage = null;
delete $nextPage;
$startRecord = null;
delete $startRecord;
$endRecord = null;
delete $endRecord;

} // end of updateTop

function cleanup() {
delete updateTopObj;
delete day;
delete page;
}

</script>


<title>Events</title>
</head>
<body onUnload="cleanup();">
<div class="whiteSubmenu"><table id="DayMenuTable" border="0"><tbody></
tbody></table> </div>
<div class="tableSpacer"></div>
<div class="whiteSubmenu"><table id="PageMenuTable"
border="0"><tbody></tbody></table> </div>
<div id="RecordsMenuTable" border="0"></div>
<hr>
<div id="dayTitle" style="color:#191970;font-size:12pt"></div>
<table id="EventsTable" title="" class="mainView table-autosort">
<thead>
<tr>
<th class="table-autosort table-sortable:default"
style="cursor:pointer">Timestamp</th>
<th class="table-autosort table-sortable:default"
style="cursor:pointer">Type</th>
<th class="table-sortable:default"
style="cursor:pointer">Source</th>
<th class="table-sortable:default" style="cursor:pointer">ID</
th>
<th class="table-sortable:default"
style="cursor:pointer">Associated Alarm</th>
<th class="table-sortable:default"
style="cursor:pointer">Username</th>
<th>Description</th>
</tr>
</thead>
<tbody id="EventsBody">
</tbody>
</table>

</body>

</html>
 
Ad

Advertisements

D

David Mark

 have a php page that is leaking pretty bad. I'm not sure if this
belongs in this group or a php one but I don't think it's the php that
giving me problems.

I'm sure it isn't (unless the leaks are server side). ;)
I've tried to use tools like drip and sieve to
help narrow the problem down, but I'm not exactly sure how to fix it.

Both worthless derelicts. Use Task Manager.
I've tried nulling and deleting variables to clean stuff up but it's
still not helping. Can someone give me a hand at cleaning my code up?
I'm fairly new at the mem leak stuff. Thanks.

Piece of cake. Lose jQuery. It leaks like a sieve (among other
things). Didn't simplify your life at all, did it?
Sorry for the large amount of code.

Don't apologize. :)

[snip]
 
Ad

Advertisements

E

Evertjan.

David Mark wrote on 08 okt 2009 in comp.lang.javascript:
Piece of cake. Lose jQuery. It leaks like a sieve (among other
things). Didn't simplify your life at all, did it?

Perhaps the OQ was ment as:

"Need Memory Leak, Help!"

.... in which case jQuery could be a great help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top