Four Pillars of the Dev Party

Grow as a Team

Grow as Individuals

Learn Together

Have fun doing it

🧐

🎉

🏋️‍♂️

🙌

Geekin' Out With

Josh

Cummings

And now for a new segment! ...

Live & Learn

Life...

Let me tell you a story...

The System was simple:

1. Kids would fill out the form

2. The data (and picture) were stored in a sqlite database file

3. The file was brought back to the office and opened in the Viewer application

4. The Viewer opened the entire database so the person could easily find what they were looking for

It had only one problem...

The more successful they were the slower it ran, ultimately crashing the computer and corrupting the database...

So close!

And yet so, so far...

Ok. So what did I learn?

Memory Management

Let's talk about memory

<?php

$bool = true;

$small = 0;
$big = PHP_MAX_INT;

$text = 'Learning about memory!';

$array = [
	'getting', 'more', 'complicated'
];

$associative = [
	'how' => 'does', 'this' => 'even', 'work?'
];

$object = new StdClass();

$object->exists = true;
$object->answer = 42;

PHP & JS are Dynamically Typed Languges

Storage & Memory Terms

Bit

Byte

Double / Word

Quadrupal / Paragraph

Check out this old thing!

Complex Memory Types

Arrays

Complex Memory Types

Objects

Object Variable

Object

Pointer #1

Pointer #2

Pointer #3

Pointer #4

Integer

String

Boolean

Object

Pointer #1

Pointer #2

How does it get cleaned up?

Garbage Collection!

Garbage Collection Strategies

Reference Counting

<?php

$data = 'Hey there'; // 1

$greeting = $data; // 2

unset($data); // 1

unset($greeting); // 0 - collect

Mark & Sweep

function circularReasoning() {
	const x = {};
	const y = {};
    
	x.badIdea = y;
	y.badIdea = x;
}

circularReasoning();

The Moral of the Story

Variables take up memory. Memory is finite.

The device running your app probably has less memory than your machine.

Memory is fast, so use it, but be conscious of how it's being loaded and dumped

Avoid circular references in your code

Objects are strange birds — all references point to the same memory

Failure is not the end of the world. Live and learn.

With

Kyle Johnson

Made with Slides.com