21
Sunday, June 12, 2022 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Embed Size (px)

Citation preview

Page 1: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Memory Leaks Presentation

Matthew WelchThomas AdamAndrew Woods

Page 2: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Introduction

• What memory leakage is;• How it is handled under:

– Windows;– Linux;– MAC OS;

• Methods that the OS uses to handle memory leaks;• Various third-party applications that handle memory

leakage; • Our own conclusions about how to handle memory leakage;

Page 3: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Memory Leakage

• Continual allocation of memory to a process; • Memory is never freed;• System becomes unresponsive;

Page 4: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Windows

• Virtual Memory ;• Process creation allows entire swap file;• Dynamic Link Libraries (dll's) are usually the culprit;

Page 5: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Linux

• Linux kernel 2.2.X onwards defines Out Of Memory (OOM-killer);

• Processes therefore aren't allowed to consume the entire VM;

• Self-preservation of the kernel;• Parent/Child hierarchy of processes;• Uninterruptible sleep means the parent process must die;

Page 6: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Mac OS

• Mac OS 6 had poor memory design features;• Memory allocated via the concept of pointers;• Fragmentation;• MacOS 9 onwards uses techniques from Linux;• Memory leaks mostly confined to applications;

Page 7: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Introduction to Memory Recovery

• Plugging memory leaks is very similar to doing Garbage Collection.

• Not normally done at the OS level, but at the sandbox / virtual machine level.

• Time and performance issues.

Page 8: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Reference Counting

• References additions/deletions are kept track of.• When a block has no references, it may be deleted.• Very easy to get into a situation where memory is not

recovered.

Page 9: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Mark and Sweep

• Two stage process• Mark – System goes from known memory references

(program stack, global variables, and CPU registers)• Sweep – Any areas not marked are freed for re-use.

Page 10: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Stop and Copy

• Similar to Mark and Sweep, Works against fragmentation also

• Only instead of Sweep, allocated data is copied to a different area

Page 11: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Reference Searching

• Search of *all* memory held by the program.• Considers that any data held in memory could be a memory

reference.• Quite slow.• Single pass.• Can be done repeatedly for better performance.• May not recover all lost memory – a conservative approach.

Page 12: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Smart Pointers and Custom Libraries

• Not an algorithm, more of a programming technique.• Available for many languages, especially C, C++• Normal pointers are ‘operator overloaded’• Prevent dangling pointers, lost objects.• Can provide automatic memory freeing. • Override the standard memory allocation functions to

provide more functionality.

Page 13: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Final Note

• State of the art Garbage Collection is still improving in terms of:

• Execution time• Incremental and interruptible• Approaching suitability for near-real-time systems.

Page 14: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Taking a look at three products that are meant to make memory

management easier.

Page 15: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Why The Need For A Third Party Program

• Windows• Poorly programmed applications• Memory leaks

• Types of memory management software available – Programming Environment – Application Environment

Page 16: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Programs Available• Linux Environment

– Dynamic Leak Check– Qps– Memtester– Asmem

• Windows Environment – MemDefrag 2– MemOptimizer– MemMonster– Release RAM– RamCleaner– Clean Ram– SuperRam– Alto Memory Booster– MemTurbo

Page 17: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

MemMonster

Rating for memMonster

Price £25

Value for money 4

File Size KB 785 KB

Ease of use 3

Flexibility/Functions 3

Appearance on screen 3

Increase in performance 300%

Operating System Windows 98/ME/NT/2K/XP and 2003

Developer Magellass Corp

Rating 1 out of 5 3

Page 18: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Alto Memory Booster

Rating for Alto memory

Price £11.10

Value for money 2

File Size KB 1,573 KB

Ease of use 3

Flexibility/Functions 2

Appearance on screen 5

Increase in performance 200%

Operating System Windows 98/ME/NT/2000 and XP

Developer Alto Software

Rating 1 out of 5 3

Page 19: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

MemTurbo

Rating for memTurbo

Price £29.95

Value for money 4

File Size KB 796 KB

Ease of use 4

Flexibility/Functions 4

Appearance on screen 5

Increase in performance 200%

Operating System Windows 95/98/NT 4.0/2000 and XP

Developer SoftwareOnline

Rating 1 out of 5 4

Page 20: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

ConclusionComparing & Contrasting Software Programs Reviewed

memTurbo memMonster Alto memory

Pros Aim at a more professional due

to Advanced capabilities Reliability and robust Free support for end-user Good help guide Navigation & GUI to a high

quality and standard

Pros Most middle range of the

three packages both in features, functions and price

Easy to configure Offers settings for disk

caching Good value for money

Pros Familiarity, especially on the

desktop (icons) Windows configuration wizard for

auto-set-up Less training needed for users Easy to get started Most cost effective

Cons Least cost effective More training required

Cons Exaggerated claims for

performance (not 300% in trail review)

Navigation is poor & not clearly defined

Cons Lacking features and advanced

functions Not as an effective memory

management software program compared to memTurbo or memMonster

Double the file size compared to memTurbo & memMonster

Questionable reliability and efficiency

Top range package for middle to advance user

Middle range package for novice to beginner

Lower range package for beginner

Page 21: Saturday, 10 October 2015 Andrew Woods, Thomas Adam, Matthew Welch Memory Leaks Presentation Matthew Welch Thomas Adam Andrew Woods

Friday, April 21, 2023 Andrew Woods, Thomas Adam, Matthew Welch

Towards a Leak Free OS?

• First Line: ‘Mark and Sweep’• Second Line: Restricting the number of memory pages that

the process may consume.• Why?• Effectiveness: These methods combined should effectively:

– Prevent memory leakage, by recovering memory from leaky processes– For runaway processes, terminating them.

• Disadvantages– Timing– Interruptions for GC