Author Topic: Garbage collector in O2  (Read 82 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Sr. Member
  • ****
  • Posts: 269
Garbage collector in O2
« on: December 05, 2018, 06:08:42 PM »
Hello Charles

how to get Garbage collector in O2 to run ?

in C# we can force the GC to run programmatically by issueing this command under certain conditions

Code: [Select]
System.GC.Collect()


Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 665
    • Charles Pegge
Re: Garbage collector in O2
« Reply #1 on: December 05, 2018, 06:44:28 PM »
The garbage collectors are not designed for explicit use. They operate whenever a string is assigned, after a string expression, at the end of a function and finally, at the end of the program.

Do you have an example where explicit garbage collection might be required?

Offline Mike Lobanovsky

  • Jr. Member
  • **
  • Posts: 94
Re: Garbage collector in O2
« Reply #2 on: December 06, 2018, 12:09:40 AM »
Hi Charles,

Does the O2 GC keep track of whether strings (and possibly, objects, UDTs and/or arrays too?) are actually used in a particular function or not before it fires its GC routines that might otherwise not be necessary at all?

Can you override garbage collection in a sequence of function calls that might form up the most time-critical portion of the application, and postpone it till much less demanding moments, e.g. user I/O and the like?

If not then you aren't in total control of your app's performance, speed and throughput wise.

That's what System.GC.Collect() is meant for in managed code.
Mike
(3.6GHz Intel Core i5 w/ 16GB RAM, 2 x GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 665
    • Charles Pegge
Re: Garbage collector in O2
« Reply #3 on: December 06, 2018, 02:46:51 AM »
Hi Mike,

o2 avoids invoking unnecessary GC routines, but tends to 'collect' as soon as the strings go out of scope. You can't get it to hold back. However, there are many opportunities to optimise string management when timing is critical, like using raw bstrings instead of native o2 strings.

Offline Chris Chancellor

  • Sr. Member
  • ****
  • Posts: 269
Re: Garbage collector in O2
« Reply #4 on: December 06, 2018, 01:22:50 PM »
Charles

the example code that i have is written in C# , it is an implementation of grid ( or Listview) and large string arrays
where GC needs to be invoked periodically during screen refreshing ( redrawing)

i'm just exploring ways to translate it to O2