# OOP and RAM usage

**URL:** <https://forum.kirupa.com/t/oop-and-ram-usage/263345>\
**Category:** programming\
**Created:** [June 14, 2008, 7:37pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345 "2008-06-14T19:37:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [June 14, 2008, 7:37pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/1 "2008-06-14T19:37:08Z")

</div>

I have a PHP class in a large 200KB file. When I do:

```php

include_once('myClass.php');
$theClass = new myClass();

```

what exactly is loaded into the server’s RAM? Is it the whole 200KB (fields + functions) or only the class fields? Are function definitions only loaded into RAM when they’re called? Should I split this big class into many sub-classes to boost server performance?

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 14, 2008, 7:52pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/2 "2008-06-14T19:52:20Z")

</div>

No, splitting them won’t do much. If you’re concerned with the memory usage of your scripts, monitor them with

[http://us3.php.net/memory\_get\_usage](http://us3.php.net/memory_get_usage)

---

<div class="post-metadata">

**Author:** ![Esherido](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/esherido/32/2158_2.png) [@Esherido](https://forum.kirupa.com/u/Esherido)\
**Post date:** [June 14, 2008, 10:11pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/3 "2008-06-14T22:11:16Z")

</div>

You might want to split it up, and then only load sub-classes of it **when** you need them.

---

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [June 14, 2008, 10:31pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/4 "2008-06-14T22:31:47Z")

</div>

Two conflicting opinions above: 😑

---

<div class="post-metadata">

**Author:** ![Esherido](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/esherido/32/2158_2.png) [@Esherido](https://forum.kirupa.com/u/Esherido)\
**Post date:** [June 14, 2008, 10:34pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/5 "2008-06-14T22:34:57Z")

</div>

The reason my split would be more efficient is because the include would be located inside a function, which you would only call when you need the classes, sub-classes, or functions located inside that file.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 14, 2008, 10:36pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/6 "2008-06-14T22:36:43Z")

</div>

But it doesn’t matter, really. When you cache a class it’s available throughout the pipe, not just for the current socket…

---

<div class="post-metadata">

**Author:** ![gregmax](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gregmax](https://forum.kirupa.com/u/gregmax)\
**Post date:** [June 15, 2008, 11:17pm UTC](https://forum.kirupa.com/t/oop-and-ram-usage/263345/7 "2008-06-15T23:17:59Z")

</div>

Wow, this is very interesting to me. I have always wondered how much memory is being used when I create a class or include a file with PHP… and what should be the maxmium or how much I should stay away from (err… if that could be judged or something, probably depends on the content or site).

May I ask what you guys are getting when you use the function memory\_get\_usage(true) at the very end of your scripts (after the HTML)? (it also helps to divide by 1024 twice…) I am asking just because I am curious of what the average is… thanks
