Should objects delete themselves in C++?

You have made Update a virtual function, suggesting that derived classes may override the implementation of Update. This introduces two big risks. 1.) An overridden implementation may remember to do a World.Remove, but may forget the delete this. The memory is leaked. 2.) The overridden implementation calls the base-class Update, which does a delete this, … Read more

Trick behind JVM’s compressed Oops

For a detailed explanation of compressed oops, see the “Compressed oops in the Hotspot JVM” article by John Rose @ Oracle. The TL;DR version is: on modern computer architectures, memory addresses are byte addresses, Java object references are addresses that point to the start of a word1, on a 64-bit machine, word alignment means that … Read more

Create a figure that is reference counted

If you create the figure without using plt.figure, then it should be reference counted as you expect. For example (This is using the non-interactive Agg backend, as well.) from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure # The pylab figure manager will be bypassed in this instance. # This means that `fig` will … Read more

What is the difference between a __weak and a __block reference?

From the docs about __block __block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame … Read more

Java Memory explained (SUN JVM)

Here’s a list of resources I had noted down. Some of these explain how the heap/garbage collection works and some have details on how to configure everything. IBM How does garbage collection work? Detailed description of garbage collection Generational and concurrent garbage collection Sun Turbo-charging Java HotSpot Virtual Machine, v1.4.x to Improve the Performance and … Read more

How to serialize a large graph of .NET objects into a SQL Server BLOB without creating a large buffer?

There is no built-in ADO.Net functionality to handle this really gracefully for large data. The problem is two fold: there is no API to ‘write’ into a SQL command(s) or parameters as into a stream. The parameter types that accept a stream (like FileStream) accept the stream to READ from it, which does not agree … Read more