- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我的混合模式 C++ 应用程序中,我注意到以下奇怪的效果:
我读到 .Net 有 2 秒的清理超时。这是针对整个非托管全局变量销毁吗?或者这是每个析构函数?
我很确定这 2 秒超时是原因,因为当我在 doexit 方法的开头设置断点时,调试器会在应用程序退出时停在那里。但是,如果我在 doexit 函数末尾附近设置断点,则永远不会命中该断点。
有没有办法从应用程序中更改这个 2 秒超时?问题是,如果不是所有的全局变量都被破坏,我的内存泄漏检测系统将报告大量内存泄漏。
编辑:
这是一个显示问题的示例程序。
因为我想制作一个混合模式的应用程序,所以我编写了一个单独的主函数( native 编译)和一个单独的“添加”函数(编译托管)。这是主要的:
#include <iostream>
#include <windows.h>
extern int add(int,int);
class X
{
public:
X(char *name) : m_name(name) {std::cout << "Constructing " << m_name << std::endl;}
~X() {Sleep(1000); std::cout << "Destructing " << m_name << std::endl;}
private:
char *m_name;
};
X x1("x1");
X x2("x2");
X x3("x3");
X x4("x4");
X x5("x5");
int main()
{
std::cout << "In beginning of main" << std::endl;
int i = add(1,2);
std::cout << i << std::endl;
std::cout << "At end of main" << std::endl;
}
这是 add.cpp 文件:
int add (int one, int two)
{
int result = one;
result += two;
return result;
}
它们是使用这些命令编译和链接的(使用 VS2010 和 .Net 4.0):
cl /c /EHsc /Od /Zi main.cpp
cl /c /Od /Zi /clr add.cpp
link /debug /debugtype:cv main.obj add.obj mscoree.lib nochkclr.obj /nodefaultlib:libcmt.lib
如果应用程序运行,这是输出:
Constructing x1
Constructing x2
Constructing x3
Constructing x4
Constructing x5
In beginning of main
3
At end of main
Destructing x5
所以全局变量的销毁在第一个之后就停止了。
如果我将 sleep 时间从 1000 毫秒减少到 500 毫秒,全局变量 x5、x4 和 x3 会被破坏,但随后它也会停止。
我将文件上传到http://www.mediafire.com/?gil2hm2d3cw1zmz , 所以如果你想测试这个,你不必再次复制/粘贴或重新键入所有内容。
编辑: 稍微更改了标题,以便更清楚地说明问题的实际原因。
最佳答案
嗯确认问题。我需要考虑/阅读更多相关内容。它开始看起来像一个错误,真的。
注意 我从来没有通过调试运行任何这些,因为我的 VS 设置不知何故很无聊。感谢您进行命令行构建!
作为记录,这是我在 Win7-64、.NET 4.0、两个 CPU 内核和 1Gb RAM 上的初始运行(没有重新编译,只是您的二进制文件):
C:\stacko>.\main.exe
Constructing x1
Constructing x2
Constructing x3
Constructing x4
Constructing x5
In beginning of main
3
At end of main
Destructing x5
Destructing x4
Destructing x3
在本地再次编译并没有改变任何东西。我仔细检查了这确实是一个混合模式的神器:
C:\stacko>cl /c /EHsc /Od /Zi main.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
C:\stacko>link main.obj
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
C:\stacko>.\main.exe
Constructing x1
Constructing x2
Constructing x3
Constructing x4
Constructing x5
In beginning of main
At end of main
Destructing x5
Destructing x4
Destructing x3
Destructing x2
Destructing x1
检查:确认。
关于.net - 由于 2 秒超时,并非所有 native 全局变量都在混合模式 .Net 应用程序中被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6028884/
在这种情况下,我们在应用程序中同时使用react-native-gesture-handler Touchable和react-native Touchable。 (通过Touchables,我的意思
我有一个 MainFooter包含页脚和迷你播放器的组件,单击时动画显示为全 View 。我有一个问题,每当我们点击一个页脚选项卡时,播放器最大化然后卡在那里,没有响应。 此外,播放器内部的向下箭
我在 native react 之上使用 native 基础组件,我想知道如何在 UI 中使卡片呈圆形而不是矩形。有圆形的 Prop 吗? 最佳答案 好吧,实际上没有人能回答这个问题,但幸运的是我在
我在 native react 之上使用 native 基础组件,我想知道如何在 UI 中使卡片呈圆形而不是矩形。有圆形的 Prop 吗? 最佳答案 好吧,实际上没有人能回答这个问题,但幸运的是我在
我是 react-native 的新手,所以我认为“HTML”而不是“native”可能有点太多了,所以我的问题看起来很愚蠢。 我使用 react-native-router-flux 进行路由,并使
当我使用这个例子在我的应用程序上实现 Image-slider 时,我遇到了这个错误。 import React,{Component} from 'react' import {View,T
我正在为我们的产品使用“Native Base”组件,并且效果很好, 但我有一点被卡住了,它是关于将 Items 放入 Nativebase Picker 的问题。我的代码是这样的 渲染方法代码 -
正如文档中所建议的,我将一些长的数据获取代码移动到 native 模块中以释放 JS 线程,但我观察到这仍然阻塞了 UI。为什么会这样,我能做些什么来避免这种情况? 从 JS 调用 native 模块
我正在使用一个名为 react-native-svg 的框架在 React Native View 中绘制 SVG 元素。 我的目标是,当我点击 View 时(我在全局 View 上使用 PanRes
在 IOS 中发现错误 Native Module cannot be null 我不使用 react-native-push-notification 最佳答案 这通常发生在您未能将第三个库链接到您
当应用程序关闭时,我可以获得由 Linking.getInitialURL() 点击的深层链接网址。 .当应用程序处于后台状态时,则不会安装任何内容。所以,我什至无法通过 Linking.addEve
1) 说原生库是什么意思?什么样的图书馆?那些将用作 gradle 依赖项? 2)如何链接这些?我在使用 link 或 rnpm 时遇到了麻烦。 最佳答案 链接 native 库意味着您要将已经实现的
我需要帮助来构建我的 react 原生项目。我尝试过react-native run-android,但出现以下错误: react-native : The term 'react-native' i
我需要帮助来构建我的 react 原生项目。我尝试过react-native run-android,但出现以下错误: react-native : The term 'react-native' i
我是 React-Native 的新手,到目前为止我很喜欢它。我正在尝试创建一个屏幕(用于跨平台应用程序),右上角有一个菜单图标,单击时,我想打开一个菜单,希望使用 react-native-menu
RN doco 和其他示例展示了如何从 native iOS View Controller 启动 React-Native View ,但反之则不然。谁能解释一下我该怎么做? 最佳答案 我能够弄清楚
对于 react-native - WebStorm 用户: 我正在使用 Jet Brains IDE WebStorm 开始一个带有 React Native 的项目。 在项目 => node_mo
在升级过去的 react-native 0.60 之后......我被警告我应该取消链接所有手动链接的第 3 方库(因为 RN 现在通过自动链接处理它)。 但是,当我运行 react-native u
你可以使用像 https://github.com/tolu360/react-native-google-places 这样的库吗?在世博项目中?我假设任何 npm 库都可以添加,但是像这个 goo
我主要喜欢 React Native。自 0.22 以来一直在使用它。目前为 0.35。 但是为什么链接原生库就像抽奖一样呢?我很少在第一次拍摄时让它发挥作用,而破裂的东西通常是完全不同的东西。 每个
我是一名优秀的程序员,十分优秀!