# Remove() and images

**URL:** <https://discourse.processing.org/t/remove-and-images/37756>\
**Category:** Beginners\
**Created:** [June 29, 2022, 12:10pm UTC](https://discourse.processing.org/t/remove-and-images/37756 "2022-06-29T12:10:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caw](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@caw](https://discourse.processing.org/u/caw)\
**Post date:** [June 29, 2022, 12:10pm UTC](https://discourse.processing.org/t/remove-and-images/37756/1 "2022-06-29T12:10:48Z")

</div>

I have a misunderstanding about images and ‘removing’ them.  
The [remove()](https://p5js.org/reference/#/p5.Graphics/remove) function in p5.js

> Removes a Graphics object from the page and frees any resources associated with it.

and one of the examples is:

```auto
let bg;
function setup() {
  bg = createCanvas(100, 100);
  bg.background(0);
  image(bg, 0, 0);
  bg.remove();
}

```

But this little fragment does not work:

```auto
let at;

function preload() {
  at = loadImage("./assets/img.jpg");
}

function setup() {
  createCanvas(400, 400);
  image(at, 0, 0);
}

function draw() {
  at.remove();
  noLoop();
}

```

fails with:

> Uncaught TypeError: at.remove is not a function

loadImage returns at p5.Image, but that does not have a remove() method (hence my error).

So the `bg` object in the first bit of code (which can be used as an argument to image) is clearly a very different beast from the `at` object in my code.

What is the difference?

I can hide/show a div to get the effect I want, but I’m still interested in the clearing up my lack of understanding!

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 29, 2022, 2:13pm UTC](https://discourse.processing.org/t/remove-and-images/37756/2 "2022-06-29T14:13:18Z")

</div>

On your 1st example, **[remove()](https://p5js.org/reference/#/p5.Element/remove)** is a method from class [p5.Element](https://p5js.org/reference/#/p5.Element).

However on your 2nd example, you’re attempting to invoke **remove()** on a [p5.Image](https://p5js.org/reference/#/p5.Image) object, which strangely doesn’t have 1.

BtW, once something is drawn on a canvas invoking **remove()** won’t remove it from that canvas. Use [**background()**](https://p5js.org/reference/#/p5/background) instead.

---

<div class="post-metadata">

**Author:** ![caw](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@caw](https://discourse.processing.org/u/caw)\
**Post date:** [June 29, 2022, 11:02pm UTC](https://discourse.processing.org/t/remove-and-images/37756/3 "2022-06-29T23:02:21Z")

</div>

Ah yes - that makes sense. Thanks for taking the time to answer.
