Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 617665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:27:38+00:00 2026-05-13T18:27:38+00:00

I am experimenting with WPF and re-implementing my old maze screensaver. My code basically

  • 0

I am experimenting with WPF and re-implementing my old maze screensaver.

My code basically adds a bunch of images to the canvas, building up a grid, 64×64 pixel images side by side, to cover the entire canvas. Then I “animate” movement in the maze, which is supposed to scroll the maze around, by adjusting a translate transformation, and swapping out the images.

However, it seems I have a leak of some sort. Whenever I resize the window, I want to re-build the image components in order to cover the form again, either with more or fewer images.

If I drag the lower left corner of the form around in tight circles the rebuild part gets slower and slower.

To remove the old controls I simply did this:

_Canvas.Children.Clear();

is this enough? Due to the slowdown I assume it isn’t.

However, since the maze is currently not “discovered” by the “avatar”, the maze images are drawn with 25% opacity, and I would assume that if I failed to remove them, I would get many images on top of each other, but it doesn’t appear to be that either.

I am caching the image sources, the image components are created like this:

_Images = new Image[(int)width, (int)height];
for (int x = -1; x < width - 1; x++)
{
    for (int y = -1; y < height - 1; y++)
    {
        Image i = new Image();
        i.Width = 64;
        i.Height = 64;
        i.Source = _Outside;
        Canvas.SetLeft(i, x * 64);
        Canvas.SetTop(i, y * 64);
        _Canvas.Children.Add(i);
        _Images[x + 1, y + 1] = i;
    }
}

Afterwards they’re assigned images to show like this:

Maze.Square sq = _Maze[_TopLeftMazeX + x, _TopLeftMazeY + y];
Image img = _Images[x + 1, y + 1];

if (sq.Seen)
    img.Opacity = 1.0;
else
    img.Opacity = 0.25;
switch (sq.Type)
{
    case Maze.SquareType.Hallway:
        img.Source = _Hallway;
        break;

    case Maze.SquareType.Wall:
        img.Source = _Wall;
        break;

    case Maze.SquareType.Outside:
        img.Source = _Outside;
        break;
}

What else should I look for? Is there a need to dispose of the image components in any way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:27:38+00:00Added an answer on May 13, 2026 at 6:27 pm

    Calling _Canvas.Children.Clear(); will remove all references to the images from the visual tree, so there are no leaks there. You may want to check for old image references being held in _Images, or some other collection you might be maintaining. For instance, you said that you were caching the image sources – doing this inefficiently, or maintaining an ever-growing list of stale images will definitely impact your system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 470k
  • Answers 470k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Problem fixed. MinGW\bin folder did not have the file libexpat-1.dll… May 16, 2026 at 2:58 am
  • Editorial Team
    Editorial Team added an answer # Needed gems. Add to your Gemfile if you are… May 16, 2026 at 2:58 am
  • Editorial Team
    Editorial Team added an answer No, it is not more effecient. Opening and Closing TCP… May 16, 2026 at 2:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.