Could someone please help me figure out why the memory usage
fluctuates when I use mysql_real_esca pe_string? I'm finding (what I
think are) memory leaks with a few mysql functions in php and I'm
trying to figure them all out. This one is pretty vexing. Thanks in
advance.
Here is example code:
class memTest {
function __construct() {
$con = mysql_connect(" *************** ","*******","** **");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("*******", $con);
mysql_query("SE T NAMES 'utf8'");
for ($i = 1; $i<=10; $i++) {
$temp = 'mysql';
echo "mem: ", memory_get_usag e(), "\n";
echo mysql_real_esca pe_string($temp ), "\n";
echo "mem: ", memory_get_usag e(), "\n\n";
}
mysql_close($co n);
}
}
$a = new memTest();
Here is what is output:
mem: 43216
mysql
mem: 43208
mem: 43208
mysql
mem: 43216
mem: 43216
mysql
mem: 43224
mem: 43224
mysql
mem: 43232
mem: 43232
mysql
mem: 43240
mem: 43240
mysql
mem: 43248
mem: 43248
mysql
mem: 43256
mem: 43256
mysql
mem: 43264
mem: 43264
mysql
mem: 43272
mem: 43272
mysql
mem: 43280 5 2403 vi***@thoughtco nvergence.com wrote:
Could someone please help me figure out why the memory usage
fluctuates when I use mysql_real_esca pe_string? I'm finding (what I
think are) memory leaks with a few mysql functions in php and I'm
trying to figure them all out. This one is pretty vexing. Thanks in
advance.
Sorry, not able to reproduce here:
mem: 99552
mysql
mem: 99552
mem: 99552
mysql
mem: 99552
mem: 99552
mysql
mem: 99552
mem: 99552
mysql
mem: 99552
(Keep in mind that I use a amd64 processor, so the 64-bit addresses waste a
lot of memory).
Question: does the memory usage go up and up, or does the garbage collector
come after some time (hint: go wild with the loop count)?? You may just be
creating temporal variables to hold the result of mysql_real_esca pe_string,
that aren't collected thereafter.
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org- http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.20-1-amd64 kernel, KDE 3.5.7, and PHP
5.2.3-1 generating this signature.
Uptime: 02:43:00 up 18 days, 10:13, 5 users, load average: 1.72, 1.78,
1.95 vi***@thoughtco nvergence.com wrote:
Could someone please help me figure out why the memory usage
fluctuates when I use mysql_real_esca pe_string? I'm finding (what I
think are) memory leaks with a few mysql functions in php and I'm
trying to figure them all out. This one is pretty vexing. Thanks in
advance.
Here is example code:
class memTest {
function __construct() {
$con = mysql_connect(" *************** ","*******","** **");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("*******", $con);
mysql_query("SE T NAMES 'utf8'");
for ($i = 1; $i<=10; $i++) {
$temp = 'mysql';
echo "mem: ", memory_get_usag e(), "\n";
echo mysql_real_esca pe_string($temp ), "\n";
echo "mem: ", memory_get_usag e(), "\n\n";
}
mysql_close($co n);
}
}
$a = new memTest();
Here is what is output:
mem: 43216
mysql
mem: 43208
mem: 43208
mysql
mem: 43216
mem: 43216
mysql
mem: 43224
mem: 43224
mysql
mem: 43232
mem: 43232
mysql
mem: 43240
mem: 43240
mysql
mem: 43248
mem: 43248
mysql
mem: 43256
mem: 43256
mysql
mem: 43264
mem: 43264
mysql
mem: 43272
mem: 43272
mysql
mem: 43280
And you're worried about *164 bytes* of memory?
Do you actually have a problem? Or are you doing "premature optimization"?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
On Jul 3, 6:42 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
v...@thoughtcon vergence.com wrote:
Could someone please help me figure out why the memory usage
fluctuates when I use mysql_real_esca pe_string? I'm finding (what I
think are) memory leaks with a few mysql functions in php and I'm
trying to figure them all out. This one is pretty vexing. Thanks in
advance.
Here is example code:
class memTest {
function __construct() {
$con = mysql_connect(" *************** ","*******","** **");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("*******", $con);
mysql_query("SE T NAMES 'utf8'");
for ($i = 1; $i<=10; $i++) {
$temp = 'mysql';
echo "mem: ", memory_get_usag e(), "\n";
echo mysql_real_esca pe_string($temp ), "\n";
echo "mem: ", memory_get_usag e(), "\n\n";
}
mysql_close($co n);
}
}
$a = new memTest();
Here is what is output:
mem: 43216
mysql
mem: 43208
mem: 43208
mysql
mem: 43216
mem: 43216
mysql
mem: 43224
mem: 43224
mysql
mem: 43232
mem: 43232
mysql
mem: 43240
mem: 43240
mysql
mem: 43248
mem: 43248
mysql
mem: 43256
mem: 43256
mysql
mem: 43264
mem: 43264
mysql
mem: 43272
mem: 43272
mysql
mem: 43280
And you're worried about *164 bytes* of memory?
Do you actually have a problem? Or are you doing "premature optimization"?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
I am doing premature optimization. Eventually I'm going to be looping
~3.5 million times and inserting data into a table, so any memory leak
will be a problem.
Interestingly, when I increase the loop count to 1000, the memory
seems to stop increasing and stabilizes at iteration 256 (2^8). Prior
to that, the memory usage increases by 8 bytes each iteration. I'd
like to know why it increases in the first place, and how to prevent
it from increasing. Is there a way to force garbage collection in php? vi***@thoughtco nvergence.com wrote:
On Jul 3, 6:42 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>v...@thoughtco nvergence.com wrote:
>>Could someone please help me figure out why the memory usage fluctuates when I use mysql_real_esca pe_string? I'm finding (what I think are) memory leaks with a few mysql functions in php and I'm trying to figure them all out. This one is pretty vexing. Thanks in advance. Here is example code: class memTest { function __construct() { $con = mysql_connect(" *************** ","*******","** **"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db ("*******", $con); mysql_query("SE T NAMES 'utf8'"); for ($i = 1; $i<=10; $i++) { $temp = 'mysql'; echo "mem: ", memory_get_usag e(), "\n"; echo mysql_real_esca pe_string($temp ), "\n"; echo "mem: ", memory_get_usag e(), "\n\n"; } mysql_close($co n); } } $a = new memTest(); Here is what is output: mem: 43216 mysql mem: 43208 mem: 43208 mysql mem: 43216 mem: 43216 mysql mem: 43224 mem: 43224 mysql mem: 43232 mem: 43232 mysql mem: 43240 mem: 43240 mysql mem: 43248 mem: 43248 mysql mem: 43256 mem: 43256 mysql mem: 43264 mem: 43264 mysql mem: 43272 mem: 43272 mysql mem: 43280
And you're worried about *164 bytes* of memory?
Do you actually have a problem? Or are you doing "premature optimization"?
-- ============== ==== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstuck...@attg lobal.net ============== ====
I am doing premature optimization. Eventually I'm going to be looping
~3.5 million times and inserting data into a table, so any memory leak
will be a problem.
Interestingly, when I increase the loop count to 1000, the memory
seems to stop increasing and stabilizes at iteration 256 (2^8). Prior
to that, the memory usage increases by 8 bytes each iteration. I'd
like to know why it increases in the first place, and how to prevent
it from increasing. Is there a way to force garbage collection in php?
Nope, no way to force garbage collection. It's not a separate thread
like in Java; the interpreter will clean things up when it gets around
to it.
But again, I wouldn't worry about it until you have a problem. With
3.5M iterations, you'll have other problems than memory leaks - for
instance, it's probably going to take a lot of time to do that many
inserts into a database.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
Jerry Stuckle wrote:
>Is there a way to force garbage collection in php?
Nope, no way to force garbage collection. It's not a separate thread
like in Java; the interpreter will clean things up when it gets around
to it.
But again, I wouldn't worry about it until you have a problem. With
3.5M iterations, you'll have other problems than memory leaks - for
instance, it's probably going to take a lot of time to do that many
inserts into a database.
And it would take even more time if you forced the garbage collector to run
more frequently than needed...
Instead of that, try experimenting with prepared statements, COPY
statements and different DB interfaces; those decisions can lead to very
different times when inserting that volume of information in the DB.
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org- http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.20-1-amd64 kernel, KDE 3.5.7, and PHP
5.2.3-1+b1 generating this signature.
Uptime: 21:37:58 up 20 days, 5:08, 5 users, load average: 3.24, 3.37,
1.52 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ranjeet.gupta |
last post by:
Dear All
Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.
Juts Theoritical Assumtion below:
|
by: José Joye |
last post by:
Hi,
I have implemented a Service that is responsible for getting messages from a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I...
|
by: Don Nell |
last post by:
Hello
Why is there a memory leak when this code is executed.
for(;;)
{
ManagementScope scope = new ManagementScope();
scope.Options.Username="username";
scope.Options.Password="password";
scope.Path.Path=@"\\pc\root\cimv2";
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex matches are called
within a loop (like if or for). E.g.
for(int i = 0; i < 10; i++)
{
Regex r = new Regex();
|
by: James |
last post by:
The following code will create memory leaks!!!
using System;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
namespace MemoryLeak
| |
by: Adrian |
last post by:
Hi
I have a JS program that runs localy (under IE6 only) on a PC but it has
a memory leak (probably the known MS one!)
What applications are there that I could use to look at the memory usage of
each object within my JS app to help locate my problem?
Thanks
|
by: Jim Land |
last post by:
Jack Slocum claims here
http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript-
memory-leaks/
that "almost every site you visit that uses JavaScript is leaking memory".
Anybody know anything about this?
Does *Javascript* leak memeory, or
does the *browser* leak memory?
|
by: ndlarsen |
last post by:
Hello.
It's been a while since I used php. Since then magic quotes has been
deprecated and will be removed when php 6.0 hits. My question is, what
should I be using when submitting data to a database instead? Which is
better for security reasons, addslashes() or mygql_real_escape_string()?
Thanks you.
Regards
|
by: Peter |
last post by:
I am using VS2008.
I have a Windows Service application which creates Crystal Reports. This is
a multi theaded application which can run several reports at one time.
My problem - there is a memory leak someplace. I can not detect the memory
leak by running several reports by hand, but when I run tha app as a
servrice and process few hundred reports there is significant memory leak.
The application can consume over 1GB of memory where it...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |