# Memory leak strategies?

**URL:** <https://forum.castle-engine.io/t/memory-leak-strategies/1069>\
**Category:** Uncategorized\
**Created:** [January 27, 2024, 8:01pm UTC](https://forum.castle-engine.io/t/memory-leak-strategies/1069 "2024-01-27T20:01:21Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)\
**Post date:** [February 17, 2024, 6:53pm UTC](https://forum.castle-engine.io/t/memory-leak-strategies/1069/14 "2024-02-17T18:53:13Z")

</div>

I can reproduce the leak in the Terrain demo as well. I add a viewport and remove its items, then in the TViewmain.Start I set:

```auto
  Viewport1 := DesignedComponent('Viewport1') as TCastleViewport;
  Viewport2 := DesignedComponent('Viewport2') as TCastleViewport;
  Viewport2.Items := Viewport1.Items;
  Viewport2.Camera := Viewport1.Camera;                 

```

The rate the memory is consumed appears to be based on the size of the viewport2. So this one is pretty big so memory is going fast.  
(32bit, win10)

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/1/15612bcd390052878a4cc8d57ff0615ffc596a92.jpeg)

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/8/860bde5175e4ec18611a3bda206c15ec28c7f6ca.jpeg)  
Here it has eaten 170mb doubling memory usage in just a few minutes. (0.6mb/second)  
 ![image](https://forum.castle-engine.io/uploads/default/original/2X/8/884080ae43c9c85e5af8f4a6e1200b487847e657.png)  
Here is the whole folder minus exe.  
[terrain.zip](https://forum.castle-engine.io/uploads/short-url/uDVeYOnTrEiU9LRc9S7bca73ZOX.zip) (11.7 MB)

---

_[View the full topic](https://forum.castle-engine.io/t/memory-leak-strategies/1069)._
