- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在开始这个问题时,我会指出我是网络开发的新手。
现在进入正题:我最近构建了一个相当小的 Flask
应用程序,它加载数据然后使用 bokeh
输出数据的可视化。因此,它必须在内存中存储大量数据(大约 10-20 MB)。这本身并不是真正的问题,但是,应用程序不会在 View 函数发送请求后释放内存中的对象。这意味着该应用仅使用几次后就会耗尽大部分内存。
因此我的问题是:如何在 View 函数返回任何请求后强制 Flask
释放使用的对象?还是我以错误的方式解决这个问题?值得一提的是,我使用了 Flask
的内置服务器,因为我们仍然只是原型(prototype)设计。¨谢谢,廷吉斯
编辑 这是我的 View 函数之一。它所做的是使用 SQLAlchemy
从数据库加载数据,然后进行一些时间序列操作(例如内核密度估计和计算累积返回)并输出连接的 div
bokeh
图形的script
字符串,即以_plt
结尾的变量。
from app import app
from app.business_logic.classes.interface_classes import Company
from app.business_logic.functions.functions import get_session
@app.route('/analysis_tool/company_performance', methods=['GET', 'POST'])
def analysis_tool__company_performance():
session = get_session()
companies_to_analyse = {
'Company A': {'ts_to_use': 'Returns of Company A'},
'Company B': {'ts_to_use': 'Returns of Company B'}
}
chosen_company = request.form.get('security')
types_of_plots = {}
if chosen_company is not None:
company = Company(session, chosen_company)
company.load_company()
company.load_timeseries(companies_to_analyse[chosen_platform]['ts_to_use'])
company.unpack_observations_of_ts_as_df()
ret_df = company.manipulate_dataframe('convert timeseries to returns',
frequency='monthly',
ts_type=company.loaded_ts_orm_obj.ts_type_name)
cum_ret_df = company.manipulate_dataframe('calculate cumulative return', df=ret_df)
cum_ret_plt = company.plot_dataframe(cum_ret_df, legend=False)
kde_plt = company.plot_kde(ret_df)
types_of_plots = {'Cumulative_return': cum_ret_plt, 'KDE': kde_plt}
return render_template('plotting/plot_using_panels.html',
items=sort_dictionary(platforms_to_analyse),
plot_types=sort_dictionary(types_of_plots),
selected=chosen_company)
这有帮助吗?
EDIT 2 我尝试了以下 question 中提供的解决方案, 通过在每次调用绘图接口(interface)和函数之后添加一个 gc.collect()
@app.teardown_request
def teardown_request(exception):
gc.collect()
但是内存还没有释放。
最佳答案
您是否有可能在 get_session
和 Company 对象之间创建循环引用?
关于python - Flask 不释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34794863/
我有一个附加了 View Controller 的 AVAudioPlayer 实例。 @property (nonatomic, retain) AVAudioPlayer *previewAudi
我是java初学者。假设我声明了一个 Account 类型的变量 Account _account = new Account("Thomas"); 然后在其他地方我做了这样的事情: _account
我在我的应用程序中使用了 3 个 UIViewController,现在我想知道当我从另一个应用程序切换到另一个 UIViewController 时释放它们是否是一个好主意。显然,这将是隐藏的,当它
我分配了一个直接缓冲区: ByteBuffer directBuffer = ByteBuffer.allocateDirect(1024); 我读过: Deallocating Direct Buf
场景。我有一个图表,我可以使用右键单击来执行平移。这非常有效。然后我完美地添加了右键菜单。 问题。现在,即使在拖动操作完成后释放鼠标,也会显示右键菜单。 有没有办法在 Java Swing 或 Jav
我使用此代码获取 ABPerson 的姓氏 CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABP
目前,我们在基于 C 的嵌入式应用程序中使用 malloc/free Linux 命令进行内存分配/取消分配。我听说这会导致内存碎片,因为内存分配/取消分配会导致堆大小增加/减少,从而导致性能下降。其
当我尝试释放缓冲区时遇到问题。每次我尝试将缓冲区传递给释放方法时,都会发生段错误。 Valgrind 确认段错误位于 BufferDeallocate 方法中。 ==30960== Memcheck,
我想知道何时按下或释放修改后的键(Ctrl 或 Shift)。 基本上,用户可以在按下修改键的情况下执行多次击键,而我不想在它被释放之前执行一个操作(想想 Emacs 和 Ctrl + X + S).
我编写了一个相当大的网络应用程序。它运行良好一段时间,然后慢慢开始运行缓慢,因为 DOM 节点开始爬升到 80,000 - 100,000 左右。 所以我一直在 Chrome 开发工具控制台 (DCT
我知道在像 c 这样的语言中,我需要在分配内存后释放它。 (我来自 Java),对此我有几个问题: 当我在做的时候: int array[30]; (即创建一个大小为 30 个整数的数组)与
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How to release pointer from boost::shared_ptr? Detach
我有一个可以从多个后台线程访问的类,可能同时访问。我无法复制该类,因为重新创建它的内容(处理或内存方面)可能很昂贵。 也有可能在后台处理仍在继续并访问该属性时替换了此类的属性。 目前我有定期的保留/释
这个问题是对: 的扩展链接-1:Creating an image out of the ios surface and saving it Link-2:Taking Screenshots fro
我有一个实例变量 NSMutableArray* searchResults。 首先,我初始化它: self.searchResults = [[NSMutableArray alloc] init]
如果我在堆上声明一些东西,比如 char *a=new char[1000] 并且主程序停止,如果没有 delete[]<,那么分配的内存会发生什么 调用?它保留在堆上还是自动释放? 最佳答案 就C+
在开发相机应用时,我遇到了一个异常,该异常仅在我切换到其他应用时发生(onPause() 用于我的应用)。 01-15 17:22:15.017: E/AndroidRuntime(14336): F
使用 JDK 1.8 编译时出现 maven 编译器错误 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (de
将 BufferedImage 保存到磁盘(以释放内存)的最快方法是什么? 我的 Java 应用程序处理大量图像(每约 300 毫秒将图像加载到内存中)。大多数这些图像都会立即被丢弃 (gc),但每隔
使用 JDK 1.8 编译时出现 maven 编译器错误 未能在项目 DUMMY 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:
我是一名优秀的程序员,十分优秀!