How do I do End Layout?

Get help using Construct 2

Post » Tue Feb 16, 2016 3:15 pm

Going from a layout to another one, instances are deleted, but the texture for the sprite object stays in memory.

If you keep piling memory (or memory leak) perhaps do you have some loop in your code that tries to create/destroy objects which could cause such an issue.

C2 has its own garbage collection so you don't have to worry about this normally, unless you're going against this logic somehow.
Debug/profile your project to see what may be going on.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
268
S
96
G
67
Posts: 7,219
Reputation: 73,729

Post » Tue Feb 16, 2016 3:25 pm

Phoenixbowman wrote:There ought to be a function that checks to see if Sprites are used on the next layout. If they are, then there should be the option to flush them from memory. That way, they're not piling up.


Uhhm. Yes and No.

Actually, Construct 2 adds and flushes images based on what you put inside the layout.

For example: If I add an image of "Player1" in "Layout1" but did not add it in "Layout2" then If I go from "Layout1" and go to "Layout2" then the memory will flush "Player1" when I go to "Layout2". That is because Construct 2 only preloads or adds images from what Construct 2 sees inside the layout. Thats why if we have an event that will create objects, we need to make sure that the images of the objects are all added in the layout
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
51
S
17
G
90
Posts: 1,108
Reputation: 59,024

Post » Tue Feb 16, 2016 3:28 pm

I did read that Ashley tutorial document. Those are general tips. Saying "Read this" doesn't address a specific cause as to why the memory keeps climbing up and up.

Something is making it go up and up. I read that, and it did not help.
B
18
S
5
G
1
Posts: 229
Reputation: 2,240

Post » Tue Feb 16, 2016 3:30 pm

Kyatric wrote:Going from a layout to another one, instances are deleted, but the texture for the sprite object stays in memory.

If you keep piling memory (or memory leak) perhaps do you have some loop in your code that tries to create/destroy objects which could cause such an issue.

C2 has its own garbage collection so you don't have to worry about this normally, unless you're going against this logic somehow.
Debug/profile your project to see what may be going on.


No, no loops in my code that create/destroy objects.
B
18
S
5
G
1
Posts: 229
Reputation: 2,240

Post » Tue Feb 16, 2016 3:31 pm

@Phoenixbowman - Okay I understand. Can you show us a .capx file because guessing will be the only thing we can do without much information.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
51
S
17
G
90
Posts: 1,108
Reputation: 59,024

Post » Tue Feb 16, 2016 3:52 pm

I ran it again and it's doing fine. I added End of Layout > Destroy Background to each level.

The background is high resolution (the only high-res graphic.) that may have been what was causing it.

In the debugger, I noticed that even when timescale was set to 0, it was still doing collision checks. Sprites on future levels don't move until the layout begins, correct? If the Sprite is set to 0, until the code making it move runs (when the layout is active) it stays still?

Unless Sprites are loaded and moving in Layouts that are not. Sprites are supposed to move, but the Layouts where they're moving are not active yet. As in, when the Layout is active, they move. What i'm getting is that Sprites are not loaded until the Layout is loaded. Meaning they should not be moving.

Because when the Layout loads, the Sprites are where I placed them in the Layout view. Which means they are not moving when the layout is not active. Yet the debugger shows collision checks.

If the Sprites on inacvtive, future, layouts are not moving, how can there be collision checks when timescale = 0

Im concerned about this because I don't want to melt the phones of people who get this game. Better to solve it now, then end up wrecking peoples' phones.
B
18
S
5
G
1
Posts: 229
Reputation: 2,240

Post » Tue Feb 16, 2016 4:00 pm

PS: The memory dropped! When I changed layouts it was fluctuating up and down, instead of only climbing.

All I did was do End of Layout > Destroy all (Except, I listed every single asset and set each one to Destroy.)

I don't know, maybe it had to do something with my code. whatever it is, it worked.

I'm just going to call it "magic" and take it.
B
18
S
5
G
1
Posts: 229
Reputation: 2,240

Post » Tue Feb 16, 2016 4:01 pm

Phoenixbowman wrote:I ran it again and it's doing fine. I added End of Layout > Destroy Background to each level.

The background is high resolution (the only high-res graphic.) that may have been what was causing it.

In the debugger, I noticed that even when timescale was set to 0, it was still doing collision checks. Sprites on future levels don't move until the layout begins, correct? If the Sprite is set to 0, until the code making it move runs (when the layout is active) it stays still?

Unless Sprites are loaded and moving in Layouts that are not. Sprites are supposed to move, but the Layouts where they're moving are not active yet. As in, when the Layout is active, they move. What i'm getting is that Sprites are not loaded until the Layout is loaded. Meaning they should not be moving.

Because when the Layout loads, the Sprites are where I placed them in the Layout view. Which means they are not moving when the layout is not active. Yet the debugger shows collision checks.

If the Sprites on inacvtive, future, layouts are not moving, how can there be collision checks when timescale = 0

Im concerned about this because I don't want to melt the phones of people who get this game. Better to solve it now, then end up wrecking peoples' phones.


Good thing that you fixed it. I am curious, what is the imagesize of your background? Is it a whole sprite? Just for future reference.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
51
S
17
G
90
Posts: 1,108
Reputation: 59,024

Post » Tue Feb 16, 2016 4:16 pm

Phoenixbowman wrote:PS: The memory dropped! When I changed layouts it was fluctuating up and down, instead of only climbing.

All I did was do End of Layout > Destroy all (Except, I listed every single asset and set each one to Destroy.)

I don't know, maybe it had to do something with my code. whatever it is, it worked.

I'm just going to call it "magic" and take it.


It's great that it is fixed but try to find the problem in the future because normally unused images are automatically removed on start of layout.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
51
S
17
G
90
Posts: 1,108
Reputation: 59,024

Post » Tue Feb 16, 2016 5:20 pm

The Image Background is just a little over 700 kilobytes.
B
18
S
5
G
1
Posts: 229
Reputation: 2,240

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: alextro, christina, Kyatric, omnipaws and 8 guests