473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

memory leakage

pradeepjain
563 512MB
Hii guys,
can any one explain me what is memory leakage .And how to prevent is in code.And any way to check memory leakage.




thanks,
Pradeep
Oct 3 '08 #1
2 1338
coolsti
310 100+
I don't think you ever have to be concerned about memory leaks with PHP.

Memory leaks occur when your program reserves memory to dynamically create an object in your program, and then all of the references to that object are destroyed without formally releasing the memory again. The operating system, e.g. Windows, will continue to see this memory as being reserved and will not be able to use it again until you reboot your computer. Since all of the references to the object in your program have been destroyed, your program can no longer release this memory.

Dynamic objects are created by allocating memory on what is called the heap, and the variable in your program is just a reference to that object, it just points to it. If you then break the connection between that reference and the object's memory that it is pointing to, without releasing (unreserving) the memory, you get a memory leak. If this keeps happening again and again in your program, at some point your operating system runs out of available memory because everything is reserved for these no longer existing objects.

Here an example:
Expand|Select|Wrap|Line Numbers
  1. // something maybe from C++
  2. MyClass myObject = new MyClass();
  3. ...
  4. // reuse the reference myObject for another object
  5. myObject = new MyClass();
  6.  
Its been a long time since I programmed C++, so maybe I don't get it all right. But the idea is that I created a reference myObject that points to a new object of my class MyClass, and this allocates memory on the heap. Later, I forget to "destroy" (tell the code to unreserve) the object, and then reuse the reference myObject in creating a new object and reserving more memory. The original memory is now reserved and unusable for anyone.

This is what a memory leak is basically all about.

However, unless I am wrong, this is nothing you need to worry about with PHP. When a script is finished running, I believe the PHP interpreter releases all memory and all system resources that the script has used, it does this for you automatically.
Oct 3 '08 #2
Atli
5,058 Expert 4TB
Yea this is not something you need to worry about with PHP.

Memory leaks are usually only found in programs that have direct access to the memory, like C/C++ for example.

In PHP, as well as most modern languages (like Java and C#), the interpreter will manage this for you automatically. It will allocate memory for you variables for you and release them when they are no longer needed.

But...
If you are creating a resource intense application in PHP, you may need to unset variables to make sure you are not using to much memory.

Like say, if your application is processing a lot of images you may want to unset the variables when they are no longer needed to free up memory for the rest of the process.
Processing ten 1MB images one after the other will build up to 10MB of memory used unless you tell PHP to unset the variables when you are done with each one.
Oct 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: frustrated | last post by:
Before I begin, I must first make the following disclaimer: Although I have considerable programming experience, I do not consider myself by any means to be an expert C++ programmer. The following...
2
by: Sambucus | last post by:
Hi group! I am using C++ and java with JNI to get some text in a RICHEDIT to my java program. I do so by accessing a C++ method every second. It all works fine except that it leaks memory every...
7
by: andylcx | last post by:
hi all: I have a code like below, is there any serious memory leakage in my code. I am confusion now but no idea how to fix it. In the member function of class A, I create a new object of class B...
10
by: s.subbarayan | last post by:
Dear all, I happen to come across this exciting inspiring article regarding memory leaks in this website: http://www.embedded.com/story/OEG20020222S0026 In this article the author mentions:...
18
by: Ramasubbu Ramasubramanian XR (AS/EAB) | last post by:
What is memory leakage, could any one explain with sample code
1
by: Gaël | last post by:
Hi everybody! I have a really big problem with ASP.NET application. I noticed that the w3wp.exe memory size, increase with the time and the use of my website. When it raise a certain value, w3wp...
0
by: kiran kumar | last post by:
Hi All, I am working on embedded python on C these days. I feel there is a memory leakage in this code. I have used our own memory pool and all the python code will use the heap from this memory...
14
by: madhawi | last post by:
i want to know that on what situation memory leakage happan and what is the solution to solve the problem of memory leakage.
3
by: Godzilla | last post by:
Hello, I have a program that create and pop an object off a queue, but it is experiencing some memory leakage. I have been unable to detect where the memory leakage occur. The strange thing is...
11
by: prpradip | last post by:
I have an ImageList (_imageList). In _imageList I have put large numbers of Icons. Now what I need is to get Handle of all Icons that I put in _imageList, so that I can destroy (DestoryIcon) them...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.