What's the difference between debug mode and release mode?


I integrated some c++ codes into electron. It works good in debug mode, but when i try with release mode, electron crashed.

I think there are some differences between debug mode and release mode that cause this problem. But i can not find what causes the problem. I find this document says the differences is only link different type of Chromium’s components and some different link settings. But i don’t know why one may cause the issue.

Electron crashed caused by my new c++ codes. It is hard to debug electron. I am not sure if anyone can give me some help.

Thanks in advanced.


After debugging, i found it is because Buffer passed from js to c++ is invalid in c++ side. The codes may look like this:

// js codes
fs.readFile(file_path, function(err, data) {
    if (err) return;
   // nativeFunction is implemented in c++   

// c++ codes
void nativeFunction(const FunctionCallbackInfo<Value>& args) {
  Local<Object> jpegBuff = info[0].As<Object>();
  SaveToPersistent("buff", jpegBuff);
  char *_buffer = node::Buffer::Data(jpegBuff);

When i set a breakpoint to check the value of _buffer, found the value is invalid, the output is

(lldb) p (int)printf("%x", *((unsigned char*)_buffer));
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0xff).

It is strange that:

  • there is not error with debug mode
  • only reading some files have the issue


The data is valid in js side.


I found it is the problem that my c++ codes uses libjpeg and libpng, and libchromiumcontent also ship with libpng.a and libjpeg_turbo.a, so they conflict. When using release mode, electron will link static libraries shipped by libchromiumcontent, that’s why it only has problem in release mode. Because ‘DEAD_CODE_STRIPPING’: ‘YES’ setting make compiling success.

Now i compile my c++ codes into shared library, then they will not have problem.